The global star formation rates (SFR) of galaxies at fixed stellar masses increase with redshift and are known to vary with environment unto z~2. We explore here whether the changes in the star formation rates can also apply to the electron densities of the inter-stellar medium (ISM) by measuring the [OII] (3727A/3729A) ratio for cluster and field galaxies at z~2. We measure a median electron density of ne = 366+/-84 cm-3 for six galaxies (with 1-sigma scatter = 163 cm-3) in the UDS proton-cluster at z=1.62. We find that the median electron density of galaxies in the UDS photo-cluster environment is three times higher compared to the median electron density of field galaxies (ne = 113+/- 63 cm-3 and 1-sigma scatter = 79 cm-3) at comparable redshifts, stellar mass and SFR. However, we note that a sample of six photo-cluster galaxies is insufficient to reliably measure the electron density in the average porto-cluster environment at z~2. We conclude that the electron density increases with redshift in both cluster and field environments up to z~2 (ne = 30 +/- 1 cm-3 for z ~ 0 to ne =254+/- 76 cm-3 for z~1.5). We find tentative evidence (~2.6 sigma ) for a possible dependence of electron density on environment, but the results require confirmation with larger sample sizes.