  We investigate the properties of neutral and charged pions in a constant
background magnetic field mainly at zero temperature within the
Nambu--Jona-Lasinio model. In the previous calculations, the Ritus method,
involving Schwinger phases in a fixed gauge, was employed within the
momentum-space random phase approximation (RPA)~[Phys. Lett. B $\textbf{782}$,
155-161 (2018)]. However, gauge invariance of the charged pion masses has not
yet been examined. In this work, by adopting the linear response theory based
on the imaginary-time path integral formalism, we derive the correlation
functions for pions in the coordinate space, where the corresponding Schwinger
phases show up automatically. At sufficiently large imaginary time $\tau$, the
meson correlation function approaches an exponential form $\sim\exp(-E_{\rm
G}\tau)$, where $E_{\rm G}$ is the ground-state energy of the one-meson state
and hence determined as the meson mass. Furthermore, we show that the mass of
the charged pions is gauge independent, i.e., independent of the choice of the
vector potential for the magnetic field. Actually, we also find that the
momentum-space RPA is equivalent to the imaginary-time method used here.
