Numerous studies have demonstrated that multiple intrinsic and extrinsic factors shape the structure and composition of gut microbiota in a host. The disorder of gut microbiota may trigger various host diseases. Here, we collected fecal samples from wild-caught Japanese geckos (Gekko japonicus) and captive conspecifics fed with mealworms (mealworm-fed geckos) and fruit flies (fly-fed geckos), aiming to examine dietary and sexual correlates of gut microbiota. We used the 16S rRNA gene sequencing technology to determine the composition of gut microbiota. The dominant phyla with a mean relative abundance higher than 10% were Verrucomicrobiota, Bacteroidota and Firmicutes. Gut microbial community richness was higher in mealworm-fed geckos than in fly-fed and wild geckos, and community diversity was higher in mealworm-fed geckos than in wild geckos. Neither alpha nor beta diversity of gut microbiota differed among wild, mealworm-fed and fly-fed geckos. The beta rather than alpha diversity of gut microbiota was sex-dependent. Based on the relative abundance of gut bacteria and its gene functions, we concluded that gut microbiota contributed more significantly to the host’s metabolic and immune functions. Higher diversity of gut microbiota in mealworm-fed geckos could result from higher chitin contents of insects of the order Coleoptera. This study not only provides basic information about the gut microbiota of G. japonicus, but also shows that gut microbiota correlates with dietary habit and sex in the species.