During the launch process of an electromagnetic railgun, the armature is subjected to the ampere force and moves along the rail with variable acceleration. In this period, the rail is excited by time varying moving loads and generates lateral vibration. For analysis, the rail is simplified as an Euler–Bernoulli beam, and the nonlinear dynamic equation of the beam under time varying moving loads is established. The electromagnetic repulsive force between rails, the contact pressure between the armature and the rail, and the thermal expansion pressure acting on the rail are taken into account. The lateral vibration response of the rail is achieved by using the analytical method combined with numerical integration. The variable motion of the armature during launch is also illustrated. Furthermore, the study of the effects of structure parameters on the vibration amplitude of the rail is performed. The research results can provide a theoretical basis for the structural optimization and vibration reduction of electromagnetic railguns.