An optical method for measuring the gas density by monitoring the refractive index inside a high-finesse Fabry–Perot cavity is presented. The frequency of a narrow linewidth Er:fiber laser, locked to a mode of the cavity, is measured with the help of an optical frequency comb while the gas density inside the cavity changes. A resolution of 1.4 × 10-6 mol m-3 is achieved in 3 s for nitrogen, which allows measurement of a relative gas density change of 3.4 × 10-8 at atmospheric pressure.