Carotenoids are membrane-bound pigments that are essential for photosynthesizing plants and algae. These specialized metabolites are widely applied in food, feed and cosmetics because of their antioxidant and anti-inflammatory properties. The production of carotenoids, particularly C30 forms, has also been documented in a few non-photosynthetic prokaryotes. However, our understanding of the function, distribution and ecology of these compounds beyond photosynthesizing organisms is limited. In this study, we performed an eco-evolutionary analysis of terpenoid biosynthetic gene clusters in the Lactobacillaceae family, an important family of beneficial bacteria with diverse lifestyles and habitats. Hereto, 4203 dereplicated genomes were screened for terpenoid biosynthesis genes, resulting in detection of crtMN genes in 28/361 (7.7%) species in 14/34 (41.2%) genera. These genes encode the key enzymes that transform two farnesyl pyrophosphate molecules into the C30 carotenoid 4,4’-diaponeurosporene. These crtMN genes appeared to be convergently gained within Fructilactobacillus, and horizontally transferred across species and genera, e.g. from Lactiplantibacillus to Levilactobacillus. Subsequently, in our in-house Lactobacillaceae culture collection from various habitats (n = 575), the phenotype was confirmed in 87% of the isolates predicted to have the crtMN genes (27/31). Nomadic and insect-adapted species, particularly those isolated from vegetable fermentations, such as Lactiplantibacillus, and floral habitats, such as Fructilactobacillus, were capable of C30 carotenoid biosynthesis, while vertebrate-associated species, such as those from the vagina, lacked this trait. This habitat association aligned with the observations that C30 carotenoid-producing strains were more resistant to oxidative and UV-stress. Taken together, this study revealed that C30 carotenoid biosynthesis plays a role in habitat adaptation and is scattered across Lactobacillaceae in line with this habitat adaptation.