How to Install R on Ubuntu 20.04

How to Install R on Ubuntu 20.04

It is an open-source programming language and free environment that specializes in statistical computing and graphical representation. It is mainly used by statistics and data miners to develop statistical software and conduct data analysis.

This article covers the steps needed to install R on Ubuntu 20.04.


Make sure you have fulfilled the following prerequisites before continuing with this tutorial:

  • Your system has at least 1G of RAM. If not, create a swap file.
  • You are logged in as a user with sudo privileges.

Install R on Ubuntu

The R packages that are included in the Ubuntu default repository often expire. We will install R from the CRAN repository.

To install R on Ubuntu 20.04, follow these steps:

1. Install the dependencies needed to add a new repository via HTTPS:

sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common

2. Add a CRAN repository to your system’s source list:

sudo apt-key adv --keyserver --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9sudo add-apt-repository 'deb focal-cran40/'

3. Install R by typing:

sudo apt install r-base

4. The installation may take several minutes to complete. When finished, verify by printing the R version:

R --version

Output :

R version 4.0.1 (2020-06-06) -- "See Things Now"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

That’s all, R has been installed on your Ubuntu machine, and you can start using it.

Arrange Package R

One of the main reasons why R is so popular is the variety of packages available through Comprehensive R Archive Network (CRAN).

To be able to compile R packages, you need to install the build-essential package:

sudo apt install build-essential

For demonstration purposes, we will install a package called stringr, which provides a fast and correct implementation of general string manipulation.

When started as root, packages will be installed globally and available to all system users. If you start R without sudo, a personal library will be prepared for your users.

Open console R:


Output :


Install the stringr package by typing:


The installation will take time and once completed, load the library with:


Create a simple character vector named tutorial:

tutorial <- c("How", "to", "Install", "R", "on", "Ubuntu", "20.04")

Run the following function which prints the length of the string:


Output :

[1] 3 2 7 1 2 6 5

You can find more R packages in Available CRAN Packages By Name and install with install.packages ().


We have shown you how to install R on Ubuntu 20.04 and compile the R package.

If you experience problems or get feedback, leave a comment below.

Related posts

How to Install KVM on Ubuntu 20.04 LTS


How to use Modprobe Commands on Linux


How to compile the ONLYOFFICE Document Server from source code on Ubuntu


How to Install the SNMP Cacti Monitoring Tool on Debian 10


How to Install Flatpaks on Ubuntu 20.04


How to Install Memcached on Ubuntu 20.04 LTS


How to Install Nextcloud with Nginx and Let’s Encrypt SSL on Ubuntu 20.04 LTS


How to Set Up an FTP Server on Ubuntu


How to install Grafana Enterprise Edition on Ubuntu Server 20.04