Resource conservation and environmental protection have become a priority development trend of rail transit. As magnesium alloy is the most effective lightweight material for its low density, high strength, and strong shock absorption, its large–scale application in rail vehicles contributes to lightweight, energy saving, and emission reduction. It is imperative to vigorously develop magnesium alloy with better properties, which may be closely related to its precipitate phases. However, research on the mechanical properties of β′ phase of different Mg–RE alloys is still insufficient. Therefore, the structure of β′ phase in Mg–RE (RE = Y, Gd, Tb, or Dy) alloys is constructed and its formation energies, electronic structures, elastic moduli, and elastic anisotropy were calculated by the first–principles method in this paper. The calculation results of formation enthalpy and elastic constants verify that these four alloys (Mg–Y, Mg–Gd, Mg–Tb, and Mg–Dy) are thermodynamically and mechanically stable. Moreover, the calculations of elastic modulus demonstrate that with RE addition, the elastic modulus are obviously improved, especially in Young's modulus which improvs from 9 to 18 GPa. Vickers hardness of β′ phase in Mg–RE alloys is calculated by the elastic moduli, which shows that Mg–RE alloys exhibit better hardness than that of α–Mg. The elastic anisotropy for each Mg–RE alloy is characterized by elastic anisotropic factors, three–dimensional views and projections of bulk, shear, and Young's moduli. The degree of anisotropy of elastic modulus are as follows: β′–Mg7Tb > β′–Mg7Y > β′–Mg7Gd > β′–Mg7Dy. The density of states and electron localization function indicate that strong metallic bonds forming between RE atoms and their neighbouring Mg atoms make contributions to their better mechanical properties. The Abovementioned results will provide beneficial data references for the Mg alloy design and characterization.