Previous work using ancestral state reconstruction of habitat salinity preference proposed that the early cyanobacteria likely lived in a freshwater environment. The aim of this study was to test that hypothesis by performing phylogenetic analyses of the genes underlying salinity preferences in the cyanobacteria. Phylogenetic analysis of compatible solute genes shows that sucrose synthesis genes were likely ancestral in the cyanobacteria, and were also likely inherited during the cyanobacterial endosymbiosis and into the photosynthetic algae and land plants. In addition, the genes for the synthesis of compatible solutes that are necessary for survival in marine and hypersaline environments (such as glucosylglycerol, glucosylglycerate, and glycine betaine) were likely acquired independently high up (i.e., more recently) in the cyanobacterial tree. Because sucrose synthesis is strongly associated with growth in a low salinity environment, this independently supports a freshwater origin for the cyanobacteria. It is also consistent with geologic evidence showing that the early oceans were much warmer and saltier than modern oceans—sucrose synthesis alone would have been insufficient for early cyanobacteria to have colonized early Precambrian oceans that had a higher ionic strength. Indeed, the acquisition of an expanded set of new compatible solute genes may have enabled the historical colonization of marine and hypersaline environments by cyanobacteria, midway through their evolutionary history.