Building R from source


If you build R from source, ensure that you have the build dependencies required for R and that you configured the build with –enable-R-shlib.

On RedHat/CentOS you can discover dependencies manually or automatically. If you want to discover packages automatically, you should enable the Extra Packages for Enterprise Linux (EPEL). EPEL hosts a seperate repository for each version of RedHat/CentOS; make sure you enable the correct repository and then use this command:

$ sudo yum-builddep R

If yum-builddep is missing:  sudo yum install yum-utils

The yum-builddep command searches the local repositories in the system and installs the build dependencies for R. If the package does not exist in the local repository it will return an error code. You will probably have to run yum-builddep followed by yum install multiple times as you install all the packages necessary to install R. Note that if your system identifies packages dependencies not available from any repository you will have to install those packages manually.

On Debian/Ubuntu systems the process is similar, but you will need to install a CRAN mirror in the sources list (/etc/apt/sources.list). This example is a source for the RStudio CRAN mirror for Ubuntu 16.04 Xenial Xerus.

deb xenial/

Once the cran mirror has been set up you can use this command to install package dependencies:

$ sudo apt-get build-dep r-base

Once you’ve satisfied the build dependencies, you should obtain and unarchive the source tarball for the version of R you want to install.  As an example, one mirror you can download R 3.X source from is: 

Once the source is downloaded, from within the extracted source directory, execute these commands (this example assumes you are installing R 3.2.3 into /opt/R/3.2.3):

Note: The directory specified after --prefix= will determine where R is installed to when executing the make install command.  The directory does not need to exist already, it will be created.

$ ./configure --prefix=/opt/R/3.2.3 --enable-R-shlib
$ make
$ sudo make install

Note that the –enable-R-shlib option is required in order to make the underlying R shared library available to RStudio Server.

You may also wish to link to the system BLAS libraries rather than use the R internal versions. For this you’d use the following configure command:

$ ./configure --prefix=/opt/R/3.2.3 --enable-R-shlib --with-blas --with-lapack

The BLAS libraries are not part of the open source R binaries, but they speed up calculations that are common in many analytic methods. If you are going through the effort of building R from source you probably want to take advantage of the performance benefits that are enabled by the BLAS libraries.

Optionally, you might want to point the R command to the latest R build. In this case, R version 3.2.3.

$ sudo ln -s /opt/R/3.2.3/bin/R /bin/R 

Finally, after you have installed R, you might want to check that it was compiled with all your desired capabilities (e.g. png, cairo, tcltk, etc.) with this command:

> capabilities()