We quantify the gas-phase abundance of deuterium and fractional contribution of stellar mass loss to the gas in cosmological zoom-in simulations from the Feedback In Realistic Environments project. At low metallicity, our simulations confirm that the deuterium abundance is very close to the primordial value. The chemical evolution of the deuterium abundance that we derive here agrees quantitatively with analytical chemical evolution models. We furthermore find that the relation between the deuterium and oxygen abundance exhibits very little scatter. We compare our simulations to existing high-redshift observations in order to determine a primordial deuterium fraction of (2.549 ± 0.033) × 10−5 and stress that future observations at higher metallicity can also be used to constrain this value. At fixed metallicity, the deuterium fraction decreases slightly with decreasing redshift, due to the increased importance of mass-loss from intermediate-mass stars. We find that the evolution of the average deuterium fraction in a galaxy correlates with its star formation history. Our simulations are consistent with observations of the Milky Way's interstellar medium (ISM): the deuterium fraction at the solar circle is 85–92 per cent of the primordial deuterium fraction. We use our simulations to make predictions for future observations. In particular, the deuterium abundance is lower at smaller galactocentric radii and in higher mass galaxies, showing that stellar mass loss is more important for fuelling star formation in these regimes (and can even dominate). Gas accreting on to galaxies has a deuterium fraction above that of the galaxies’ ISM, but below the primordial fraction, because it is a mix of gas accreting from the intergalactic medium and gas previously ejected or stripped from galaxies.