How long could you live on the Moon?
Short answer: You can stay on the Moon as long as you have a safe place to live, and as long as you keep getting resupplies from Earth.
Long answer: The longest anyone has stayed on the Moon so far is 74 hours, 59 minutes, 38 seconds. This was during the Apollo 17 mission in 1972. The Apollo missions weren't designed to stay on the Moon for longer than this, and the astronauts would have run out of air quickly if they had stayed any longer.
Anyone wanting to live on the Moon for a long time would need a safe habitat that protects them from extreme temperatures and long-term radiation. This could be something they build themselves, it could be something built by robots, or it could be an underground cavern such as a lava tube.
They would also need food, water and other supplies. At this stage there is no practical way to create these things on the Moon, so anyone living there would need regular supplies from Earth. This is the limiting factor—as long as you're protected from radiation and getting what you need to survive, you could stay on the Moon for the rest of your normal lifetime (more or less).
At least that's what we assume. Since no one has ever done this, we don't really know how the low gravity and other environmental factors would affect people long-term. We won't know for sure until people start doing it.
See also: