Numerous electrochemistry reactions require the precise calculation of the ion solvation energy. Despite the significant progress in the first-principles calculations for crystals and defect formation energies for solids, the liquid system free energy calculations still face many challenges. Ion solvation free energies can be calculated via different semiempirical ways, e.g., using implicit solvent models or cluster of explicit molecule models; however, systematically improving these models is difficult due to their lack of a solid theoretical base. A theoretically sound approach for calculating the free energy is to use thermodynamic integration. Nevertheless, owing to the difficulties of self-consistent convergence in first-principles calculations for unphysical atomic configurations, the computational alchemy approach has not been widely used for first-principles calculations. This study proposes a general approach to use first-principles computational alchemy for calculating the ion solvation energy. This approach is also applicable for other small molecules. The calculated ion solvation free energies for Li+, Na+, K+, Be2+, Mg2+, and Ca2+ are close to the experimental results, and the standard deviation due to molecular dynamics fluctuations is within 0.06eV.