Microbes in insect gut significantly influence host physiology. While Lepidoptera is a diverse insect order, the relationship between microbial symbiosis and host development remains elusive, especially concerning role of gut-colonizing bacteria in metamorphosis. We investigated the gut microbial diversity in Galleria mellonella throughout its life cycle using 16S rRNA amplicon sequencing. Our findings revealed a predominance of Enterococcus spp. in larvae and Enterobacter spp. in pupae. Remarkably, removing Enterococcus spp. hastened the larval-to-pupal transition. Transcriptome analysis showed an upregulation of immune response genes in pupae and hormone genes in larvae. Notably, the production of antimicrobial peptides in the host gut varied with developmental stages. Some of these peptides suppressed the growth of Enterococcus innesii, a dominant gut bacterium in G. mellonella larvae. This research underscores the pivotal role of gut microbiota shifts in metamorphosis, driven by the secretion of antimicrobial peptides in the G. mellonella digestive system.