A measurement of the production cross-section for $Z$ bosons that decay to muons is presented. The data were recorded by the LHCb detector during $pp$ collisions at a centre-of-mass energy of 7 TeV, and correspond to an integrated luminosity of 1.0 fb$^{-1}$. The cross-section is measured for muons in the pseudorapidity range $2.0 < eta < 4.5$ with transverse momenta $p_{T} > 20$ GeV/c. The dimuon mass is restricted to $60 < M_{mu^{+}mu^{-}} < 120$ GeV/c$^{2}$. The measured cross-section is $$sigma_{Zrightarrowmu^{+}mu^{-}} = (76.0 pm 0.3 pm 0.5 pm 1.0 pm 1.3) , text{pb}$$ where the uncertainties are due to the sample size, systematic effects, the beam energy and the luminosity. This result is in good agreement with theoretical predictions at next-to-next-to-leading order in perturbative quantum chromodynamics. The cross-section is also measured differentially as a function of kinematic variables of the $Z$ boson. Ratios of the production cross-sections of electroweak bosons are presented using updated LHCb measurements of $W$ boson production. A precise test of the Standard Model is provided by the measurement of the ratio $$frac{sigma_{W^{+}rightarrowmu^{+} u_{mu}} + sigma_{W^{-}rightarrowmu^{-}bar{ u}_{mu}}}{sigma_{Zrightarrowmu^{+}mu^{-}}} = 20.63pm0.09pm0.12pm0.05,$$ where the uncertainty due to luminosity cancels.