Installing R packages available for all users
Solution 1
aL3xa gives (IMHO) bad advice. Do not mess with /usr
which is handled by the package management system. Instead, use the facility provided by /usr/local/lib/R/site-library
.
That latter directory is already searched by default. All you need to do is to add yourself to group staff
as that group has write-rights there -- try adduser yourid staff
where yourid
is your user name on the system. Afterwards you should be able to install there without problems.
Another thing you may like on Ubuntu is apt-get install littler
and then use the install.r
and upgrade.r
helper scripts from the examples directory. I use them all the time.
Solution 2
aL3xa answer is wrong; you shouldn't expose those directories to write for all users.
Run R as a root (probably using sudo R
) and then install packages as usual -- they will be placed in a global library and will be available for all users.
Solution 3
In your case, the easiest way would be to install the packages as root (or as administrator in case of Windows), they'll be available for every user on that machine.
Related videos on Youtube
David B
Updated on February 28, 2020Comments
-
David B about 4 years
I have a few R packages installed under
~/R/i486-pc-linux-gnu-library/2.11
.I would like to make them, and any other R package I install from now on, available to all R users. I don't mind re-installing the packages I already have in a neutral place (they are just a few). So how do I do that?
-
aL3xa over 13 yearsNeat one, definitely a better solution, though you've advertised your product(s)... =) Is
/usre/local...
a typo? -
Dirk Eddelbuettel over 13 yearsWell my advertising budget is small :) Typo fixed -- thanks.
-
Dirk Eddelbuettel over 13 yearsOr add yourself to group
staff
as I wrote and you don't needsudo
to run as root. -
aL3xa over 13 yearsOne more question:
staff
group is another of your products (since you maintain Debian/Ubuntu packages)? It's available only on those packages? If so, I'm migrating back to Ubuntu... maybe! =) -
David B over 13 yearsso how do I set back the permissions suggested by aL3xa (I already ran the loop)
-
Dirk Eddelbuettel over 13 years
sudo chmod -R 0755 /usr/lib/library/R
as 0755 (user write, group and others r) is the default for directories. -
aL3xa over 13 yearsSorry for my "solution". I'm the one and only user, so it's "safe" to change permissions in my case.
-
David B over 13 yearsI added my user to
staff
but when trying to install a package from R I still get> install.packages("getopt") Warning in install.packages("getopt") : argument 'lib' is missing: using '/usr/local/lib/R/site-library' Warning in install.packages("getopt") : 'lib = "/usr/local/lib/R/site-library"' is not writable Would you like to create a personal library '~/R/i486-pc-linux-gnu-library/2.11' to install packages into? (y/n)
-
Dirk Eddelbuettel over 13 yearsPlease consider posting the question on r-sig-debian.
-
Janvb over 12 yearsWhere can I find more info about install.r and upgrade.r of the littler program? thanks
-
Dirk Eddelbuettel over 12 yearsThey are (really short) examples in the littler package, just as it says in the third paragraph of my answer above.
-
Serrano about 9 yearsThis answer was very helpful, but is missing a few details. After adding yourself to the
staff
group, you need to log out and back in for it to have effect (hence David B's error). But how to tell R to install in/usr/local/...
? I found one method:install.packages('foo', '/usr/local/lib/R/site-library')
. -
Dirk Eddelbuettel about 9 yearsYes, logging in and out (ie creating a new session for you) is required. The location is normally the default on Debian-based systems; littler which has been mentioned here also sets it in
install.r
and now alsoinstall2.r
. -
RockScience over 8 yearsmaintenance question: what happens if you update the packages at the same time as another user has the package loaded?
-
Lazarus Thurston over 5 yearsAfter having searched I guess this is the question that matches mine to the closest, hence not creating a new question. Request @DirkEddelbuettel to kindly enlighten us, in which situation is package installed in each of these directories:
[1] "/home/rstudio/R/x86_64-pc-linux-gnu-library/3.4" "/usr/local/lib/R/site-library" [3] "/usr/lib/R/site-library" "/usr/lib/R/library"
. It has left be floundering for answers when I see 128 packages are lying in the first directory, 90 in the second, 1 in the third and 15 in the fourth. -
Dirk Eddelbuettel over 5 years@Sanjay: This is a eight+ years old question and answer, but I answered similar questions many times over. Keep looking for other answers In short: unless something else is specified the first position in
.libPaths()
is used. -
Lazarus Thurston over 5 yearsDid a little bit more searches and the situation appears murkier than earlier. I chanced upon your excellent advice here stat.ethz.ch/pipermail/r-sig-debian/2018-May/002833.html and now am thinking if I made a mistake to leap forward to instal 3.5.2 on my ubuntu server. Would you still go by your advice of avoiding the jump, or has the situation changed and R 3.5.2 on ubuntu 16 installation is now well documented and robust?
-
Dirk Eddelbuettel over 5 years@Sanjay May I ask you to stop this subthread here? It really is not the right place. Post on r-sig-debian and describe your situation and concerns. FWIW I run the current R 3.5.2 (via the CRAN-mirrored apt repository) on several current Ubuntu 18.10 machines.