The exclusive deep inelastic electroproduction of $\psi(2S)$ and $J/\psi(1S)$ at an $ep$ centre-of-mass energy of 317 GeV has been studied with the ZEUS detector at HERA in the kinematic range $2 < Q^2 < 80$ GeV$^2$, $30 < W < 210$ GeV and $|t| < 1$ GeV$^2$, where $Q^2$ is the photon virtuality, $W$ is the photon-proton centre-of-mass energy and $t$ is the squared four-momentum transfer at the proton vertex. The data for $2 < Q^2 < 5$ GeV$^2$ were taken in the HERA I running period and correspond to an integrated luminosity of 114 pb$^{-1}$. The data for $5 < Q^2 < 80$ GeV$^2$ are from both HERA I and HERA II periods and correspond to an integrated luminosity of 468 pb$^{-1}$. The decay modes analysed were $\mu^+\mu^-$ and $J/\psi(1S) \,\pi^+\pi^-$ for the $\psi(2S)$ and $\mu^+\mu^-$ for the $J/\psi(1S)$. The cross-section ratio $\sigma_{\psi(2S)}/\sigma_{J/\psi(1S)}$ has been measured as a function of $Q^2, W$ and $t$. The results are compared to predictions of QCD-inspired models of exclusive vector-meson production. Comment: 24 pages, 8 figures