Skip to content

Instantly share code, notes, and snippets.

@magic-lantern
Last active February 1, 2019 03:47
Show Gist options
  • Save magic-lantern/1b0ac71c758cd999be9106fe1a598399 to your computer and use it in GitHub Desktop.
Save magic-lantern/1b0ac71c758cd999be9106fe1a598399 to your computer and use it in GitHub Desktop.
Steps to upgrade Ubuntu 16.04 LTS from R 3.4.x to R 3.5.x

Steps to upgrade r:

From linux command-line remove all existing R packages:

sudo apt-get update
sudo apt-get remove r-base r-base-dev r-base-core r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart  r-cran-spatial r-cran-survival r-doc-html r-recommended

Next, update /etc/apt/sources.list and add these lines (comment out old R version, add new pkg list):

# deb [arch=i386,amd64] https://cran.rstudio.com/bin/linux/ubuntu xenial/
# deb-src [arch=i386,amd64] https://cran.rstudio.com/bin/linux/ubuntu xenial/
# new version of R - 3.5.x
deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/

Then, back at the command-line, refresh the local apt cache and install R:

sudo apt-get update
sudo apt-get install r-base r-base-dev r-doc-info

Next, cleanup and left-over but no longer needed packages:

sudo apt-get autoremove

To Reload/re-install all system wide R packages

Start R as root with sudo R and then run the following:

update.packages(ask=FALSE, checkBuilt = TRUE)

The above works as the system .libPaths() on linux do not have the R version in them.

To install all previously user installed R packages

Replace <username> below with your actual username

lib_loc <- "/home/<username>/R/x86_64-pc-linux-gnu-library/3.4"
to_install <- unname(installed.packages(lib.loc = lib_loc)[, "Package"])
to_install
install.packages(pkgs = to_install)

How to only install packages not already installed

If you have a few packages that you are not sure are already installed, and don't want to go through installing if already present, use these lines, replacing list.of.packages with your own list.

From: https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them

list.of.packages <- c("pkg1", "pkg2")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment