In recent years, with the deepening understanding of the gut microbiota, it has been recognized to play a significant role in the development and progression of diseases. Particularly in gastrointestinal tumors, the gut microbiota influences tumor growth by dysbiosis, release of bacterial toxins, and modulation of host signaling pathways and immune status. Immune checkpoint inhibitors (ICIs) have greatly improved cancer treatment efficacy by enhancing immune cell responses. Current clinical and preclinical studies have demonstrated that the gut microbiota and its metabolites can enhance the effectiveness of immunotherapy. Furthermore, certain gut microbiota can serve as biomarkers for predicting immunotherapy responses. Interventions targeting the gut microbiota for the treatment of gastrointestinal diseases, especially colorectal cancer (CRC), include fecal microbiota transplantation, probiotics, prebiotics, engineered bacteria, and dietary interventions. These approaches not only improve the efficacy of ICIs but also hold promise for enhancing immunotherapy outcomes. In this review, we primarily discuss the role of the gut microbiota and its metabolites in tumors, host immunity, and immunotherapy.