Animals form complex symbiotic associations with their gut microbes, whose evolution is determined by an intricate network of host and environmental factors. In many insects, such as Drosophila melanogaster, the microbiome is flexible, environmentally determined and less diverse than in mammals. In contrast, mammals maintain complex multispecies consortia that are able to colonize and persist in the gastrointestinal tract. Understanding the evolutionary and ecological dynamics of gut microbes in different hosts is challenging. This requires disentangling the ecological factors of selection, determining the timescales over which evolution occurs, and elucidating the architecture of such evolutionary patterns. Here, we employ experimental evolution to track the pace of the evolution of a common gut commensal, Lactiplantibacillus plantarum, within invertebrate (Drosophila melanogaster) and vertebrate (Mus musculus) hosts and their respective diets. While the symbiosis between Drosophila and L. plantarum is mainly determined by host diet, with the host influencing the fitness of its gut microbes only over short timescales, bacterial evolution within the mammalian host follows a divergent evolutionary path. Here, the host and its intrinsic factors play a critical role in selection and influence both the phenotypic and genomic evolution of its gut microbes, as well as the outcome of their symbiosis.