Gut dysbiosis leads to increased intestinal permeability and alterations of the gut–liver axis, leading to liver inflammation. The reiteration of this mechanism promotes an immunosuppressive microenvironment that favors the occurrence of primary liver cancers, including HCC and CCA. Moreover, during dysbiosis, a shift in gut-derived metabolites occurs, deeply influencing tumorigenesis. Dysbiosis is associated with BA retention and increased levels of secondary BAs, especially deoxycholic acid, which drives liver damage, aberrant liver cell proliferation and HCC promotion by the downregulation of FXR expression and the upregulation of the Wnt/β-catenin pathway. In CCA, a decrease in secondary BAs and changes in the glycoconjugated to tauroconjugated BAs ratio is described. High TMAO levels deriving from bacterial choline metabolism are associated with liver cancers, whereas high-choline diets exert a protective effect. Indole derivatives are important for immune cell development and intestinal barrier protection; a reduction in indole levels is typical of chronic liver diseases and high-fat diets. Among SCFAs, butyrate seems to have contradictory effects on HCC, sustaining cancer progression in some studies, and increasing immunotherapy efficacy in others, whereas butyrate seems to reduce cell mitosis in CCA. COnversely, acetate can contrast HCC progression by ILC3 inhibition and interfering with HDAC activity. Ethanol is a well-recognized carcinogenic agent; other than diet, increased ethanol plasma levels can derive from ethanol-producing bacteria, such as Klebsiella pneumoniae, which is over-represented in gut dysbiosis. Finally, high BCAA tumor levels and high BCAA intratumor metabolism have been associated with HCC and CCA. Differently, BCAA administration with diet seems to inhibit this process, suggesting a reciprocal relationship between dysbiosis and BCAA metabolism. Abbreviations: HCC: hepatocellular carcinoma; CCA: cholangiocarcinoma; FXR: farnesoid X receptor; TMAO: trimethylamine N-oxide; SCFAs: short-chain fatty acids; HDACs: histone deacetylases; BCAAs: branched-chain amino acids; ILC3s: type 3 innate lymphoid cells; BAs: bile acids. Created with Biorender.com.