Our current understanding of immunology was largely defined in laboratory mice, partly because they are inbred and genetically homogeneous, can be genetically manipulated, allow kinetic tissue analyses to be carried out from the onset of disease, and permit the use of tractable disease models. Comparably reductionist experiments are neither technically nor ethically possible in humans. However, there is growing concern that laboratory mice do not reflect relevant aspects of the human immune system, which may account for failures to translate disease treatments from bench to bedside. Laboratory mice live in abnormally hygienic specific pathogen free (SPF) barrier facilities. Here we show that standard laboratory mouse husbandry has profound effects on the immune system and that environmental changes produce mice with immune systems closer to those of adult humans. Laboratory mice--like newborn, but not adult, humans--lack effector-differentiated and mucosally distributed memory T cells. These cell populations were present in free-living barn populations of feral mice and pet store mice with diverse microbial experience, and were induced in laboratory mice after co-housing with pet store mice, suggesting that the environment is involved in the induction of these cells. Altering the living conditions of mice profoundly affected the cellular composition of the innate and adaptive immune systems, resulted in global changes in blood cell gene expression to patterns that more closely reflected the immune signatures of adult humans rather than neonates, altered resistance to infection, and influenced T-cell differentiation in response to a de novo viral infection. These data highlight the effects of environment on the basal immune state and response to infection and suggest that restoring physiological microbial exposure in laboratory mice could provide a relevant tool for modelling immunological events in free-living organisms, including humans.