Amazon EC2: Upgrading R


After installing R and Shiny on my EC2 instance I discovered that the default version of R was a little dated and I wanted to update to R 3.2.0. It’s not terribly complicated, but here are the steps I took.

First, become root.

$ sudo /bin/bash

Remove the old version of R.

# apt-get remove r-base-core

Edit /etc/apt/sources.list and add the following:

deb trusty/

Replace trusty with the name of your Ubuntu version.

Back in the shell, add the public keys.

# gpg --keyserver --recv-key E084DAB9
# gpg -a --export E084DAB9 | apt-key add --

Update the package list and install the new base R package.

# apt-get update  
# apt-get upgrade  
# apt-get install r-base

When you launch R you should find that it is the sparkling new version.

Now you will want to update all of the packages too, so launch R (as root) and then do:

> update.packages(lib.loc = "/usr/local/lib/R/site-library", ask = FALSE)

If you have packages installed in a user library, you should update those too.

Finally, if you run into memory problems with the package updates, then you’ll need to add a swap file.

Categorically Variable