Skip to content

Updating R on Linux

Louis Maddox edited this page Jun 9, 2016 · 16 revisions

NB - if on Windows, use Tal Galili's installr (upgrade R from within R!)


  • sudo vim /etc/apt/sources.list
  • Add deb https://mirrors.ebi.ac.uk/CRAN/bin/linux/ubuntu trusty/
    • deb MIRROR_URL/bin/linux/ubuntu LINUX_CODENAME/
      MIRROR_URL : https://mirrors.ebi.ac.uk/CRAN/ — via list of mirrors here
      LINUX_CODENAME : trusty — via cat /etc/*-release
  • sudo apt-get update

Problem: GPG key has expired (R's Secure APT)

Solution: add new key given here

  • Via notes at CRAN on Secure APT via this ServerFault question
  • run sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys GPG_KEY
    GPG_KEY : currently E084DAB9 (June 2016, apparently changed mid-Oct '15)
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

  • sudo apt-get install r-base

Users who need to compile R packages from source [e.g. package maintainers, or anyone installing packages with install.packages()] should also install the r-base-dev package:

sudo apt-get install r-base-dev


* (Followed the system hint to run `sudo apt-get update` again after this step)

```sh
~ $ R

R version 3.3.0 (2016-05-03) -- "Supposedly Educational"

Upgrade complete 😎

Reinstalling packages

You could reinstall all packages in the new version of R using this trick

store_packages.R :

# store_packages.R
#
# stores a list of your currently installed packages

tmp = installed.packages()

installedpackages = as.vector(tmp[is.na(tmp[,"Priority"]), 1])
save(installedpackages, file="~/Downloads/installed_packages.rda")

restore_packages.R :

# restore_packages.R
#
# installs each package from the stored list of packages

load("~/Desktop/installed_packages.rda")

for (count in 1:length(installedpackages)) install.packages(installedpackages[count])

...however that's potentially wasteful of space, and you could instead move your packages to a new path which will persist across further upgrades, as recommended here

Here, I'm using ~/opt/R/libs/ as my new personal package library

new.lib.path <- path.expand("~/opt/R/libs/")
.libPaths(new.lib.path)

To retain this setting, edit the Rprofile.site in the R installation's /etc/ directory.

  • find (or confirm) the /etc/ location with whereis R

ls -l /etc/R/Rprofile.site -rw-r--r-- 1 root root 807 Dec 11 2014 /etc/R/Rprofile.site


* `sudo vim /etc/R/Rprofile.site` and add the `.libPaths` line above [as appropriate]
Clone this wiki locally