Skip to content

Changing the default library folder path in R

G30th November 2017

CNo Comments


A simple procedure in Microsoft Windows for setting the default library folder for installations of R.

Installations of R will tend to install libraries at C:/Program Files/R/R-X.X.X/library, which may not always be writable. The only way to effectively change this default resides outside of R in Microsoft Windows.

In the Microsoft Control Panel, go to System and Security > System > Advanced system settings > Environment variables.

Screen capture of the environment variables panel in Microsoft Windows 10.

The environment variables panel in Microsoft Windows 10.

A new environment variable should be created by clicking on “New…” and entering R_LIBS_USER as the variable name and C:\Path\To\R-Libraries as the variable path (change as appropriate).

Save the changes and restart R. Packages should now be saved to the new location.

The PowerShell Method

Another method for achieving this in the command line is via Windows PowerShell:

[Environment]::SetEnvironmentVariable("R_LIBS_USER", "C:\Path\To\R-Libraries", "User")


No comments have yet been submitted. Be the first!

Have your say:

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.