How To Install R on Ubuntu 18.04 [Quickstart]

How To Install R on Ubuntu 18.04 [Quickstart]


R is an open-source programming language that specializes in statistical computing and graphics. In this tutorial, we will install R on an Ubuntu 18.04 server.

For a more detailed version of this tutorial, with better explanations of each step, please refer to How To Install R on Ubuntu 18.04.

Step 1 — Add GPG Key

Logged into your Ubuntu 18.04 server as a sudo non-root user, add the relevant GPG key.

  1. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

Step 2 — Add the R Repository

  1. sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/'

If you’re not using 18.04, find the relevant repository from the R Project Ubuntu list, named for each release.

Step 3 — Update Package Lists

  1. sudo apt update

Step 4 — Install R

  1. sudo apt install r-base

If prompted to confirm installation, press y to continue.

Step 5 — Test Install

Start R’s interactive shell as root.

  1. sudo -i R

You should receive output similar to the following:

R version 4.0.0 (2020-04-24) -- "Arbor Day" Copyright (C) 2020 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) ... Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >

This confirms that we’ve successfully installed R and entered its interactive shell.

Here are links to more detailed tutorials that are related to this guide:

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Thanks for sharing this! I’ve tried several solutions found online, and yours is the one works. A lot of solutions I found didn’t set up step 1 and 2 correctly.

The first step is not working what do I do about the GPG Key

I am using Windows WSL Ubuntu 18.04 and I am getting this an error when running

sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'

which is

Err:8 http://cran.rstudio.com/bin/linux/ubuntu bionic/ Release
  404  Not Found [IP: 80]
Err:9 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran36/ Release
  404  Not Found [IP: 443]

This can occurr in any of the Get’s eg. in this run it occurs in Err 8 & Err 9 but last time it was 5 & 6. Any ideas?

Thank you Lisa. Once I realised the ‘relevant GPG key’ wasn’t a key unique to me I was happy :)

Thank you for thus step by step. It was really helpful.

Hi Lisa… Thanks for the post. Please i would like to know the significance of first 2 steps. i am using Ubuntu 19.04 and i just performed the 4rth step alone and got it installed by skipping the rest.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel