Installing R on Ubuntu

February 8, 2014

(This article was first published on Software for Exploratory Data Analysis and Statistical Modelling » R Environment, and kindly contributed to R-bloggers)

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.

To leave a comment for the author, please follow the link and comment on their blog: Software for Exploratory Data Analysis and Statistical Modelling » R Environment. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)