Why is .libPaths() different in RStudio vs. R?


By default, R packages are installed into a user-specific library based on the contents of the R_LIBS_USER environment variable (more details on this mechanism are here:

When you are working in R outside RStudio, R will use the default location described in the above link, unless R_LIBS_USER is set explicitly in one of the startup files: .Rprofile or

However, RStudio offers more flexibility, and will look in several places for R_LIBS_USER:

  • The /etc/rstudio/rsession-profile file
  • The user's bash profile
  • The r-libs-user setting in /etc/rstudio/rsession.conf
  • The R startup files: .Rprofile or

If R_LIBS_USER is set in more than one place, the order of precedence is:

.Rprofile or > r-libs-user in rsession.conf > user bash profile > rsession-profile

RStudio will pick it up from any of those places, but if it’s in more than one spot, that’s the order of precedence.  Additional details can be found in the Customizing Session Launches and User Library sections of the RStudio Server Pro administrator's guide.