The wild relatives of tomatoes are all native to the deserts of western South America (the Atacama Desert), but Solanum lycopersicum itself is not really known from the wild.
Tomatoes are cultivated on all continents except Antarctica, from sea level to 3000 metres elevation, and in temperate climates they are grown as an annual. Tomatoes can become weedy and escape from gardens, when they do, they can be a problem for rarer wild relatives that they can hybridise with.
Tomatoes are grown in gardens and rich soil where they escape from gardens they often grow near rubbish dumps or sewage works where soil is high in nutrients.
They can grow in quite dry areas, but grow bigger and produce more fruit when they are well-watered.