Installing R on Ubuntu

February 8th, 2014

The R statistical software is provided either as source code or pre-compiled binary files. In the majority of cases the binaries are sufficient but there may be situations where it is necessary to compile the software from source code and this post describes the steps required on an Ubuntu Linux system.

This post has taken information from various sources including the RHIPE webpage. There are various tools that need to be installed on Ubuntu to be able to build R from source code.

The R code is a mixture of Fortran and C so the tools for compiling code in these languages need to be installed:

sudo apt-get install gfortran
sudo apt-get install build-essential

The R source code can be downloaded from CRAN using the wget command so for version 3.0.3 we can use this command to download:


The source file is compressed and is extracted with the tar command and we move to the directory where the files have been copied:

tar -xzf R-3.0.3.tar.gz
cd R-3.0.3

The readline package is required for compilation:

sudo apt-get install libreadline6 libreadline6-dev

The X11 headers are also needed:

sudo apt-get install xorg-dev

It appears that java is required for the installation so we download the jdk and jre files and extract them to /usr/local/java.

sudo mkdir -p /usr/local/java
sudo cp -r jdk-8-linux-x64.tar.gz /usr/local/java
sudo cp -r jre-8-linux-x64.tar.gz /usr/local/java
cd /usr/local/java
sudo tar xvzf jdk-8-linux-x64.tar.gz
sudo tar xvzf jre-8-linux-x64.tar.gz

The following lines can be added to the .bashrc file to ensure that the paths are available for the next steps.

export JAVA_HOME
export JRE_HOME
export PATH

Then some commands are required to make java available:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.8.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.8.0/bin/javaws" 1
sudo update-alternatives --set java /usr/local/java/jre1.8.0/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jre1.8.0/bin/javaws

Finally we can configure our build options to make R as a shared library and build from source:

./configure --enable-R-shlib # --prefix=...
make install

It might be necessary to run the make command as sudo.

Comments are closed.