The detection of low-mass transiting exoplanets in multiple systems brings new constraints to planetary formation and evolution processes and challenges the current planet formation theories. Nevertheless, only a mere fraction of the small planets detected by Kepler and K2 have precise mass measurements, which are mandatory to constrain their composition. We aim to characterise the planets that orbit the relatively bright star K2-138. This system is dynamically particular as it presents the longest chain known to date of planets close to the 3:2 resonance. We obtained 215 HARPS spectra from which we derived the radial-velocity variations of K2-138. Via a joint Bayesian analysis of both the K2 photometry and HARPS radial-velocities (RVs), we constrained the parameters of the six planets in orbit. The masses of the four inner planets, from b to e, are 3.1, 6.3, 7.9, and 13.0 M ⊕ with a precision of 34%, 20%, 18%, and 15%, respectively. The bulk densities are 4.9, 2.8, 3.2, and 1.8 g cm −3 , ranging from Earth to Neptune-like values. For planets f and g, we report upper limits. Finally, we predict transit timing variations of the order two to six minutes from the masses derived. Given its peculiar dynamics, K2-138 is an ideal target for transit timing variation (TTV) measurements from space with the upcoming CHaracterizing ExOPlanet Satellite (CHEOPS) to study this highly-packed system and compare TTV and RV masses.