How To Install R on Ubuntu 18.04

The R programming language is focused on graphics and statistical computing. This language is a key asset for developers as it is used to develop statistical software as well as perform data analysis.

Being one of the most popular languages, R offers user-friendly packages for certain different study areas, making it the easiest to use in many fields.

In this article, we will show you how to install R on Ubuntu 18.04 Bionic Beaver Linux.


Before you start, make sure you have the following:

  • Ubuntu 18.04 server
  • 1GB of RAM
  • A non-root user (with Sudo privileges)

Once you have these requirements, you’re set to start.

Step 1 - Installing R

R project keeps on being updated, so the latest version may not always be available when searched in Ubuntu’s repositories. For this reason, it is recommended to begin the process using Comprehensive RArchive Network, CRAN to add the external repository.

CRAN, in this case, helps maintain the reliable repositories in a given network.

Here, you must be careful because not all third-party repositories are reliable. For this reason, always ensure you install CRAN only from reputable sources.

Start by adding the necessary GPG key.

$ sudo apt-key adv --keyserver --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

Once you run this command, you should see the output below:

Executing: /tmp/apt-key-gpghome.4BZzh1TALq/
gpg: key51716619E084DAB9: publickey"Michael Rutter <>"imported
gpg: Totalnumber processed: 1
gpg:               imported: 1

After acquiring the trusted key, now add the external repository. To find the required repository file, go to Ubuntu Packages for R list to see all the relevant repository for each releases.

$ sudo add-apt-repository 'deb bionic-cran35/'

From the information that shows on your screen, you should see the following lines:

Get:5 bionic-cran35/ InRelease [3609 B]                 
Get:6 bionic-cran35/ Packages [21.0 kB]

Once you have identified these lines, run the update to include the manifests from the new repository.

$ sudo apt update

You should see the line below from the output:

Hit:2 bionic-cran35/ InRelease

If you see this line after running the update command, then it means the new repository has been added successfully. This confirms that you have installed the latest version.

Now the platform is set, install R by running the command below:

$ sudo apt install r-base

You will be asked to confirm the installation, do so and press y to proceed.

At the time of compiling this article, the latest version of R according to CRAN is 3.5.1, which should appear once you run R.

Our plan is to install a sample package for every local user, so we will run R as root to make the libraries available to every user automatically.

Alternatively, run R command without sudo to set up a personal library for every user. To start the interactive shell of R as root, run the following command:

$ sudo -i R

You should have the following output:

 R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
Type 'demo()' for some demos, 'help()' foron-linehelp, or
'help.start()' foran HTML browser interface to help.
Type 'q()' to quit R.


This shows that R is installed successfully on your system. Now, let’s install R packages.

Now that you have successfully learned how to install R on Ubuntu system, it’s time to try if the process will work on your side.

Check out these top 3 VPS services:

Was this article helpful?