installation path not writable R, unable to update packages

81,971

Solution 1

In general, I would advise against changing the permission in system folders, because R should work without additional administrative rights.

Thus I would likewise advise against installing packages using administrative rights, as you would be required to do so in the future every time you have to update these packages!

To backtrace this issue and prevent to minimize it in future updates, you should perform the following steps:

  1. Note which packages that fail to update (already shown in the error message).
  2. Locate the folders where all R packages are installed using .libPaths(). This should provide two results, a destination in your home folder and a system folder.

"/home/USER/R/x86_64-pc-linux-gnu-library/X.X" "/usr/lib/R/library"

  1. Install the packages with install.packages(c("PKG1", "PKG2", "PKG3")) or BiocManager::install(c("PKG1", "PKG2", "PKG3"))*
  2. Only If you have administrator rights: Manually remove the older package folders from the system folder ("/usr/lib/R/library"), using administrator rights (sudo) OR enter R with administrator rights One last time and run remove.packages(c("PKG1", "PKG2", "PKG3"), lib = "/usr/lib/R/library").

*If there are issues with the installation path, add the argument , lib = "/home/USER/R/x86_64-pc-linux-gnu-library/X.X" to either of the install functions in step 3. This argument explicitly states to install in your home folder.

There is a single issue with this approach, at least with the official R repository on Arch Linux: Whenever R is updated, the updated version still includes packages in the system folder, that can't be updated without administrative rights. Therefore for each R update, this procedure must be repeated. I'm especially looking at you survival!!!

*Edit: It is important to note that biocLite is no longer the recommended tool for installing BioConductor packages. You should instead use BiocManager, which is in the official CRAN repository (install.packages("BiocManager")).

**Second edit: As this answer still receives votes, I have updated and cleaned up the answer.

Solution 2

It was a permission issue for me. First, I identified where the packages were installed using installed.packages()[, c("Package", "LibPath")]. This outputs a long 2 column matrix with the names and locations of the packages. Then you will see where the offending packages are. In my case, they were at /usr/lib/R/site-library and /usr/lib/R/library. Then I changed the permission of these folders by chmod (I used chmod -R 777 on the main R folder, this is my personal computer, so security is not a big concern here I think).

Solution 3

If you are running R/Rstudio on Windows, then just open R/Rstudio as administrator. Right click on the icon then run as administrator

Solution 4

One solution is to open a terminal and load R using admin rights

sudo R
update.packages()
source("https://bioconductor.org/biocLite.R")
biocLite()

Then you can update. But careful. This can create packages by the admin in a directory supposed to be owned by a user.

In this case, instead of loading R as root (which is solving the problem until the next update), check the .libPaths(). You will have a list of directories.

.libPaths()
"/home/it_s_me/R/x86_64-pc-linux-gnu-library/3.4" "/usr/lib/R/library"

In my case, all packages in "/usr/lib/R/library" are owned by root, and all except one are owned by a normal user (not root) at "/home/itsame/R/x86_64-pc-linux-gnu-library/3.4".

If you have admin rights, an easy solution may be to run chown in all the places: For example, I had trouble updating the curl package. I used:

sudo chown -R it_s_me /home/it_s_me/R/x86_64-pc-linux-gnu-library/3.4/curl/

Solution 5

It looks like several 'recommended' packages are installed in two places -- maybe by an administrator account in a directory you don't have write access to, and then by RStudio in a directory where you do have write access. biocLite() is complaining about the former.

Unless biocLite() complains about a Bioconductor package that cannot be installed (different from cannot be updated), there is no problem and basic Bioconductor packages have been successfully installed. Check out https://support.bioconductor.org for future Bioconductor-related support.

Share:
81,971
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying to install Bioconductor into R, using the code on their website. When I type in the code (see bellow) I get an error message saying that some packages can't be updated, the installation path is unwriteable.

    > ## try http:// if https:// URLs are not supported
    > source("https://bioconductor.org/biocLite.R")
    Bioconductor version 3.4 (BiocInstaller 1.24.0), ?biocLite for help
    > biocLite()
    BioC_mirror: https://bioconductor.org
    Using Bioconductor 3.4 (BiocInstaller 1.24.0), R 3.3.2 (2016-10-31).
    installation path not writeable, unable to update packages: Matrix, mgcv,
    

    survival

    I can install these package by going to packages/install packages.

    > utils:::menuInstallPkgs()
    trying URL    'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/Matrix_1.2-8.zip'
    Content type 'application/zip' length 2775038 bytes (2.6 MB)
    downloaded 2.6 MB
    
    trying URL 'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/mgcv_1.8-  16.zip'
    Content type 'application/zip' length 2346257 bytes (2.2 MB)
    downloaded 2.2 MB
    
    trying URL     'https://www.stats.bris.ac.uk/R/bin/windows/contrib/3.3/survival_2.40-1.zip'
    Content type 'application/zip' length 5109948 bytes (4.9 MB)
    downloaded 4.9 MB
    
    package ‘Matrix’ successfully unpacked and MD5 sums checked
    package ‘mgcv’ successfully unpacked and MD5 sums checked
    package ‘survival’ successfully unpacked and MD5 sums checked
    
    The downloaded binary packages are in
        C:\Users\stxeb8\AppData\Local\Temp\Rtmp2tQZ4v\downloaded_packages
    

    I can then go to packages/ load packages and load them succesfully and search and see that the packages are there.

    > local({pkg <- select.list(sort(.packages(all.available =   TRUE)),graphics=TRUE)
    + if(nchar(pkg)) library(pkg, character.only=TRUE)})
    Loading required package: nlme
    This is mgcv 1.8-16. For overview type 'help("mgcv-package")'.
    > local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
    + if(nchar(pkg)) library(pkg, character.only=TRUE)})
    > local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
    + if(nchar(pkg)) library(pkg, character.only=TRUE)})
    > local({pkg <- select.list(sort(.packages(all.available =     TRUE)),graphics=TRUE)
    + if(nchar(pkg)) library(pkg, character.only=TRUE)})
    > search()
    [1] ".GlobalEnv"            "package:survival"      "package:mgcv"         
    [4] "package:nlme"          "package:Matrix"        "package:BiocInstaller"
    [7] "package:stats"         "package:graphics"      "package:grDevices"    
    [10] "package:utils"         "package:datasets"      "package:methods"      
    [13] "Autoloads"             "package:base"         
    

    But then when I go to install bioconductor it gives me the same error message that Matrix, mgcv and survival aren't able to be updated.

    > ## try http:// if https:// URLs are not supported
    > source("https://bioconductor.org/biocLite.R")
    Bioconductor version 3.4 (BiocInstaller 1.24.0), ?biocLite for help
    > biocLite()
    BioC_mirror: https://bioconductor.org
    Using Bioconductor 3.4 (BiocInstaller 1.24.0), R 3.3.2 (2016-10-31).
    installation path not writeable, unable to update packages: Matrix, mgcv,
      survival
    

    What can I do to be able to update these packages so I can install bioconductor?

  • Admin
    Admin almost 7 years
    Thank you I will give this a try
  • Tyler
    Tyler about 6 years
    You don't need the pipe (or magrittr) here: installed.packages()[, c("Package", "LibPath")] does the same thing
  • rbrisk
    rbrisk almost 5 years
    On linux, those R packages are installed as OS packages, i.e. r-base depends on r-cran-matrix, r-cran-survival, and r-cran-mgcv as well as a few others. The problem with this approach is that the OS packages will be broken after the corresponding R packages are removed. Moreover, during the next OS package upgrade, the R packages will be installed again into the system directories and subsequently cause problems with Bioconductor.
  • Kasper Thystrup Karstensen
    Kasper Thystrup Karstensen over 4 years
    I still stick to my answer that packages normally never should be installed by the user, using administrator privileges!! ..BUT I see your point with these specific packages! Running R 3.6.1 (in Arch Linux) those packages seems to be integrated into the base installation, and thus I am unable to remove the packages with the method described in my answer. I can't account for earlier versions though!
  • Kasper Thystrup Karstensen
    Kasper Thystrup Karstensen over 4 years
    > remove.packages("Matrix") Removing package from ‘/home/ME/R/x86_64-pc-linux-gnu-library/3.6’ (as ‘lib’ is unspecified) Error in remove.packages : there is no package called ‘Matrix’
  • Ricardo Pietrobon
    Ricardo Pietrobon over 4 years
    @KasperThystrupKarstensen your method did work for manjaro (an arch distro). The packages were in /usr/lib/R/library. What is still puzzling is why the packages ended up installed with root in the first place: I performed a clean install, previously uninstalled R and deleted the R dir with all previous packages. No sudo used in the whole process and, yet I had four packages only accessible to root. Not sure where that came from. Anyway, the problem is solved, at least for now.
  • A1aks
    A1aks almost 4 years
    What to do if you don't have admin rights? I am a user on a large organizational server and this answer does not help.
  • Gildas
    Gildas almost 4 years
    I would recommend then installing some kind of miniconda, then create an environment for R, then you can manage the things better, at the cost of installing all the packages yourself and at the cost of those packages tacking place. You can also create a new library folder, put its path first in the libPaths()... e.g.
  • A1aks
    A1aks almost 4 years
    Thanks. But what worked for me is that there were 2 R installations done by the SystemAdmin (R-3.4.5 and R-3.6.1). The admins had made R-3.4 as the default, so whatever packages you send by the command line goes into the 3.4 lib folder. One (user and not admin) has to point out the library path in your /home folder in order to direct libraries of Bioconductor be installed. Eventually I had to do something like above .libPaths() "/home/it_s_me/R/x86_64-pc-linux-gnu-library/3.6.1" "/usr/lib/R/library"
  • Kasper Thystrup Karstensen
    Kasper Thystrup Karstensen almost 4 years
    @RicardoPietrobon Sorry for the late answer, I was uncertain before but now I'm quite sure. With every R release, packages such as survival are installed alongside R during the upgrade, and hence end up in /usr/lib/R/library. To me, this is extremely annoying, as I would expect the base developer team to not include any packages during R installations (or upgrades), and instead integrate them into the base code