The gut microbiome is associated with diverse diseases(1-3), but a universal signature of a healthy or unhealthy microbiome has not been identified, and there is a need to understand how genetics, exposome, lifestyle and diet shape the microbiome in health and disease. Here we profiled bacterial composition, function, antibiotic resistance and virulence factors in the gut microbiomes of 8,208 Dutch individuals from a three-generational cohort comprising 2,756 families. We correlated these to 241 host and environmental factors, including physical and mental health, use of medication, diet, socioeconomic factors and childhood and current exposome. We identify that the microbiome is shaped primarily by the environment and cohabitation. Only around 6.6% of taxa are heritable, whereas the variance of around 48.6% of taxa is significantly explained by cohabitation. By identifying 2,856 associations between the microbiome and health, we find that seemingly unrelated diseases share a common microbiome signature that is independent of comorbidities. Furthermore, we identify 7,519 associations between microbiome features and diet, socioeconomics and early life and current exposome, with numerous early-life and current factors being significantly associated with microbiome function and composition. Overall, this study provides a comprehensive overview of gut microbiome and the underlying impact of heritability and exposures that will facilitate future development of microbiome-targeted therapies.