Skip to content

Install R#

These instructions describe how to install R from precompiled binaries on a Linux server.

Do you need to install multiple versions of R?

Our recommended installation instructions for R allow you to make multiple versions of R available, and avoid replacing existing versions of R when updating system packages.

Install required dependencies#

To install the necessary runtime dependencies for R, you will need to enable additional repositories for third-party or source packages by using the following commands:

# Enable the Extra Packages for Enterprise Linux (EPEL) repository
$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

# Enable the CodeReady Linux Builder repository
$ sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms

# If running RHEL 9 in a public cloud, such as Amazon EC2, enable the CodeReady
# Linux Builder repository from Red Hat Update Infrastructure (RHUI) instead
$ sudo dnf install dnf-plugins-core
$ sudo dnf config-manager --set-enabled codeready-builder-for-rhel-9-*-rpms
# Enable the Extra Packages for Enterprise Linux (EPEL) repository
$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

# Enable the CodeReady Linux Builder repository
$ sudo subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms

# If running RHEL 8 in a public cloud, such as Amazon EC2, enable the CodeReady
# Linux Builder repository from Red Hat Update Infrastructure (RHUI) instead
$ sudo dnf install dnf-plugins-core
$ sudo dnf config-manager --set-enabled "codeready-builder-for-rhel-8-*-rpms"
# Enable the Extra Packages for Enterprise Linux (EPEL) repository
$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 

# On RHEL 7, enable the Optional repository
$ sudo subscription-manager repos --enable "rhel-*-optional-rpms"

# If running RHEL 7 in a public cloud, such as Amazon EC2, enable the
# Optional repository from Red Hat Update Infrastructure (RHUI) instead
$ sudo yum install yum-utils
$ sudo yum-config-manager --enable "rhel-*-optional-rpms"
$ sudo apt-get update
$ sudo apt-get install gdebi-core

Specify R version#

Define the version of R that you want to install. This environment variable will be used in all of the following steps. You can install a different version of R by specifying the desired version in this step.

Terminal
$ export R_VERSION=4.1.3
Available versions of R

Versions of R that are available include:

4.2.2, 4.2.1, 4.2.0, 4.1.3, 4.1.2, 4.1.1, 4.1.0, 4.0.5, 4.0.4, 4.0.3, 4.0.2, 4.0.1, 4.0.0


3.6.3, 3.6.2, 3.6.1, 3.6.0, 3.5.3, 3.5.2, 3.5.1, 3.5.0, 3.4.4, 3.4.3, 3.4.2, 3.4.1, 3.4.0, 3.3.3, 3.3.2, 3.3.1, 3.3.0

If you need to use an earlier version of R, then you will need to modify the export command shown above:

Terminal
$ export R_VERSION=3.X.X

Please see the cran.r-project index for all available versions of R.

R 3.3.2, 3.3.1, and 3.3.0 are only available for RHEL/CentOS 7.

Download and install R#

Download and install the desired version of R.

$ curl -O https://cdn.rstudio.com/r/rhel-9/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
$ sudo dnf install R-${R_VERSION}-1-1.x86_64.rpm
$ curl -O https://cdn.rstudio.com/r/centos-8/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
$ sudo yum install R-${R_VERSION}-1-1.x86_64.rpm
$ curl -O https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
$ sudo yum install R-${R_VERSION}-1-1.x86_64.rpm
$ curl -O https://cdn.rstudio.com/r/ubuntu-2204/pkgs/r-${R_VERSION}_1_amd64.deb
$ sudo gdebi r-${R_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/r/ubuntu-2004/pkgs/r-${R_VERSION}_1_amd64.deb
$ sudo gdebi r-${R_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/r/ubuntu-1804/pkgs/r-${R_VERSION}_1_amd64.deb
$ sudo gdebi r-${R_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/r/debian-11/pkgs/r-${R_VERSION}_1_amd64.deb
$ sudo gdebi r-${R_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/r/debian-10/pkgs/r-${R_VERSION}_1_amd64.deb
$ sudo gdebi r-${R_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/r/opensuse-154/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
$ sudo zypper --no-gpg-checks install R-${R_VERSION}-1-1.x86_64.rpm
$ curl -O https://cdn.rstudio.com/r/opensuse-153/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
$ sudo zypper --no-gpg-checks install R-${R_VERSION}-1-1.x86_64.rpm

Verify R installation#

Test that R was successfully installed by running:

Terminal
$ /opt/R/${R_VERSION}/bin/R --version

Note

This section only applies to the first installation of R on a given system. For subsequent installations, this section should be skipped.

To ensure that R is available on the default system PATH variable, create symbolic links to the version of R that you installed:

Terminal
$ sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
$ sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript

We recommend installing several optional system dependencies that are used by common R packages.

Posit Package Manager, formerly RStudio Package Manager, can automatically detect known system dependencies and provides installation commands for supported Linux operating systems. Additional information is provided in our documentation.

(Optional) Install multiple versions of R#

If you want to install multiple versions of R on the same server, you can repeat these steps to specify, download, and install a different version of R alongside existing versions.

Additional information#

Refer to the rstudio/r-builds repository on GitHub for more information on these binary distributions of R.

Follow these steps to install R from source.