How to install R in Ubuntu-based distros?

Follow the below instructions to install R in your Ubuntu distro:


First open your Terminal and run the following line:

Assuming that you are not using the "root" user which is the case in many distros. Otherwise, remove the "sudo"

sudo apt update -qq

Then run the following code to install the helper packages needed for this installation:

sudo apt install --no-install-recommends software-properties-common dirmngr

Then add the signing key (by Michael Rutter) for these repos.

# To verify key, run the following command:

gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

Fingerprint is: E298A3A825C0D65DFD57CBB651716619E084DAB9

Then run the following command:

wget -qO- | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

Then run the following command to add the R version "4" repo to your package manager:

sudo add-apt-repository "deb $(lsb_release -cs)-cran40/"

Installation of R

Now to install R and its dependencies, run the following command:

sudo apt install --no-install-recommends r-base

For more details about this version please refer to the official R read me file:

Ubuntu Packages For R - Full Instructions

Get other CRAN packages

Run the following command to add the current R 4.0 or later ‘c2d4u’ repository:

sudo add-apt-repository

You can now do apt install --no-install-recommends r-cran-rstan or apt install --no-install-recommends r-cran-tidyverse to install packages.

Please note that ‘c2d4u’ repository is only available for LTS releases. If you wish to attempt to use the repository with an non-LTS release, you can manually edit the ’c2d4u_team-ubuntu-c2d4u4_0_-*.list’ to use focal instead of the intended release. This usage of the ‘c2d4u’ repository is unsupported. An LTS release is strongly suggested for utilizing the ‘c2d4u’ repository.


The Debian R packages are maintained by Dirk Eddelbuettel. The Ubuntu packages are compiled for i386 and amd64 by Michael Rutter ([email protected]) using scripts developed by Vincent Goulet.