The relative yields of $\Upsilon$ mesons produced in pp and PbPb collisions at $\sqrt{s_\mathrm{NN}}$ = 5.02 TeV and reconstructed via the dimuon decay channel are measured using data collected by the CMS experiment. Double ratios are formed by comparing the yields of the excited states, $\Upsilon$(2S) and $\Upsilon$(3S), to the ground state, $\Upsilon$(1S), in both PbPb and pp collisions at the same center-of-mass energy. The double ratios, [$\Upsilon$(nS)/$\Upsilon$(1S)]$_\mathrm{PbPb}$ / [$\Upsilon$(nS)/$\Upsilon$(1S)]$_\mathrm{pp}$, are measured to be 0.308 $\pm$ 0.055 (stat) $\pm$ 0.019 (syst) for the $\Upsilon$(2S) and less than 0.26 at 95% confidence level for the $\Upsilon$(3S). No significant $\Upsilon$(3S) signal is found in the PbPb data. The double ratios are studied as a function of collision centrality, as well as dimuon transverse momentum and rapidity. No significant dependencies are observed.