R is an open source programming language and free environment that specializes in statistical calculations and graphical representations. It is mainly used by statisticians and data miners to develop statistical software and perform data analysis.
This article describes the steps required to install R on Ubuntu 20.04.
Make sure you meet the following requirements before proceeding with this tutorial:
- Your system has at least 1 GB of RAM. Otherwise, create a page file.
- You are logged in as a user with sudo rights.
Install R on Ubuntu
The R packages contained in the standard Ubuntu repositories are often out of date. We install R from the CRANE
To install R on Ubuntu 20.04, do the following:
Install the dependencies required to add a new repository over HTTPS:
sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
Add the CRAN repository to your list of system sources:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
Install R by typing:
sudo apt install r-base
The installation can take a few minutes. When you’re done, check it out by printing out the R version:
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 it, R has been installed on your Ubuntu computer and you are ready to use it.
Compiling R packages
One of the main reasons R is so popular is because of the wide variety of packages available through the Comprehensive R Archive Network (CRAN).
To be able to compile R packages, you must have the
sudo apt install build-essential
For demonstration purposes, we’ll install a package called
, which provides quick, correct implementations of common string manipulations.
When starting as root, the packages are installed globally and are available to all system users. If you start R without
, a personal library is set up for your user.
Open the R console:
stringr Package by entering:
The installation will take some time and when done, load the library with:
Create a simple drawing vector called
tutorial <- c("How", "to", "Install", "R", "on", "Ubuntu", "20.04")
Run the following function that returns the length of a string:
 3 2 7 1 2 6 5
You can find more R packages at Available CRAN packages by name
and install it with
We showed you how to install R on Ubuntu 20.04 and how to compile R packages.
If you run into any problem or have any feedback, please leave a comment below.