Context. Determining the mass of stars is crucial both for improving stellar evolution theory and for characterising exoplanetary systems. Asteroseismology offers a promising way for estimating the stellar mean density. When combined with accurate radii determinations, such as are expected from Gaia, this yields accurate stellar masses. The main difficulty is finding the best way to extract the mean density of a star from a set of observed frequencies. Aims. We seek to establish a new method for estimating the stellar mean density, which combines the simplicity of a scaling law while providing the accuracy of an inversion technique. Methods. We provide a framework in which to construct and evaluate kernel-based linear inversions that directly yield the mean density of a star. We then describe three different inversion techniques (SOLA and two scaling laws) and apply them to the Sun, several test cases and three stars, α Cen B, HD 49933 and HD 49385, two of which are observed by CoRoT. Results. The SOLA (subtractive optimally localised averages) approach and the scaling law based on the surface correcting technique described by Kjeldsen et al. (2008, ApJ, 683, L175) yield comparable results that can reach an accuracy of 0.5% and are better than scaling the large frequency separation. The reason for this is that the averaging kernels from the two first methods are comparable in quality and are better than what is obtained with the large frequency separation. It is also shown that scaling the large frequency separation is more sensitive to near-surface effects, but is much less affected by an incorrect mode identification. As a result, one can identify pulsation modes by looking for an and n assignment which provides the best agreement between the results from the large frequency separation and those from one of the two other methods. Non-linear effects are also discussed, as is the effects of mixed modes. In particular, we show that mixed modes bring little improvement to the mean density estimates because of their poorly adapted kernels.