Herbivorous fishes play important ecological roles in coral reefs by consuming algae that can otherwise outcompete corals, but we know little about the gut microbiota that facilitates this process. This study focussed on the gut microbiota of an ecologically important coral reef fish, the convict surgeonfish Acanthurus triostegus. We sought to understand how the microbiome of this species varies along its gastrointestinal tract and how it varies between juvenile and adult fish. Further, we examined if the bacteria associated with the diet consumed by juveniles contribute to the gut microbiota. 16S rRNA gene amplicon sequencing showed that bacterial communities associated with the midgut and hindgut regions were distinct between adults and juveniles; however, no significant differences were seen for gut wall samples. The microbiota associated with the epilithic algal food source was similar to that of the juvenile midgut and gut wall but differed from the microbiome of the hindgut. A core bacterial community including members of taxa Epulopiscium and Brevinemataceae was observed across all gastrointestinal and diet samples, suggesting that these bacterial symbionts can be acquired by juvenile convict surgeonfish horizontally via their diet and then are retained into adulthood.