The inclusive production cross sections at forward rapidity of {mathrm{J}/psi }, {psi (mathrm{2S})}, Upsilon (1S) and Upsilon (2S) are measured in mathrm{pp} collisions at sqrt{s}=7~mathrm{TeV} with the ALICE detector at the LHC. The analysis is based on a data sample corresponding to an integrated luminosity of 1.35 pb^{-1}. Quarkonia are reconstructed in the dimuon-decay channel and the signal yields are evaluated by fitting the mu ^+mu ^- invariant mass distributions. The differential production cross sections are measured as a function of the transverse momentum {p_mathrm{T}} and rapidity y, over the ranges 0<{p_mathrm{T}}<20 GeV/c for {mathrm{J}/psi }, 0<{p_mathrm{T}}<12 GeV/c for all other resonances and for 2.5<y<4. The measured cross sections integrated over {p_mathrm{T}} and y, and assuming unpolarized quarkonia, are: sigma _mathrm{{mathrm{J}/psi }}=6.69pm 0.04pm 0.63 upmu b, sigma _{psi (mathrm{2S})}=1.13pm 0.07pm 0.19 upmu b, sigma _{Upsilon (mathrm{1S})}=54.2,pm , 5.0pm 6.7 nb and sigma _{Upsilon (mathrm{2S})}=18.4,pm ,3.7,pm , 2.9 nb, where the first uncertainty is statistical and the second one is systematic. The results are compared to measurements performed by other LHC experiments and to theoretical models.