Safe and recommended alternatives have already been discussed elsewhere, so this question should probably be closed as a duplicate.
But if it's just the one package, consider doing the install as root using sudo
. This feels dirty, but if you're looking for a quick fix, this is slightly better than opening up a system directory for write access to all users henceforth. Except if that package contains malware, I guess.
It's typically advised that you don't mess with the "system" libraries, though, which are the domain of the package manager, i.e., apt
on Ubuntu. As for a better long-term alternative, the short answer is: consider using /usr/local
for locally-installed (as opposed to system-installed) packages. This is what /usr/local
is for.
You can add yourself to the staff
group on Ubuntu (or whatever particular "admin" group applies to your distro) and then grant yourself full-time access to /usr/local
like this:
# you will need to log out and back in for this to take effect
sudo usermod -aG staff $USER
# assuming a local ext3/4 filesystem
# grant 'staff' read/write for existing files r/w/x for existing dirs
sudo setfacl -R -m g:staff:rwX /usr/local
# also apply these by default to new files and directories
sudo setfacl -R -d -m g:staff:rwX /usr/local
I'm not nearly an expert with configuring R for a large site, so please do your own research. However, based on observation, /usr/local/lib/R/site-library
is already the first path in R_LIBS_SITE
as defined in the factory-installed /etc/R/Renviron
on Debian/Ubuntu, which suggests it's the correct place for a local admin to install packages.
So, if that directory exists on the filesystem and you have read/write access to it, then future install.packages
as your regular user will just "do the right thing" and go into /usr/local
:
> .Library.site
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"
> install.packages("lubridate")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
⋮
Hope that helps.