The ecological and genetic changes that underlie evolution of host-microbe interactions remain elusive, primarily due to challenges in disentangling the variables that alter microbiome composition. To understand the impact of host habitat, host genetics and evolutionary history on microbial community structure, we examined gut microbiomes of river- and three cave-adapted morphotypes of the Mexican tetra, Astyanax mexicanus, in their natural environments and under controlled laboratory conditions. We found that lab-reared fish exhibited increased microbiome richness and distinct composition compared to their wild counterparts, underscoring the significant influence of habitat. Most notably, however, we found that morphotypes reared on the same diet throughout life developed distinct microbiomes suggesting that genetic loci resulting from cavefish adaptation shape microbiome composition. We observed stable differences in Fusobacteriota abundance between morphotypes and demonstrate that this could be used as a trait for quantitative trait loci mapping to uncover the genetic basis of microbial community structure.