How to Install R on Ubuntu 20.04
Want to install R on Ubuntu? Sign up for BitLaunch here and grab a free trial.
Open-source programming language R was first launched in 1995 after its start as an inventively named spin-off from the S language. However, though it was created back when Netscape was a thing, it's still used widely today for statistical computing.
The open-source nature of R has allowed it to offer specialized packages for different areas of study by way of the community. A core package set numbering 15,000 is included with R, but a group of packages known as the "Tidyverse" is also growing in popularity.
For brevity, we won't be diving into all the details of usage in this tutorial, but we will cover how to install R on Ubuntu 20.04 and how to install some of the above packages. First, though, be aware that you'll need some pre-requisites:
- A local PC or VPS server with at least 1 GB of RAM
- A non-root user with sudo privileges
- A way to connect to your VPS, such as puTTy
Let's get started:
Install R on Ubuntu
Before we can install R on Ubuntu, we need to add the relevant GPG key to our non-root user:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
The output will look something like this:
Executing: /tmp/apt-key-gpghome.wM5sOwGHJ9/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
gpg: key 51716619E084DAB9: public key "Michael Rutter <marutter@gmail.com>" imported
Now we need to add the R repository. The one listed below is for Ubuntu 20.04, but if you're using a earlier of later version you'll want to browse for the folder here and use that instead.
sudo add-apt-repository 'https://cloud.r-project.org/bin/linux/ubuntu/focal-cran40/'
sudo apt update
You can then install R on Ubuntu via your package manager:
sudo apt install r-base
Once it's complete, type R --version
to make sure it has installed correctly. You can start it with sudo -i R
to make sure you can enter its shell.
How to install R packages
Installing additional packages for R is thankfully quite easy. We'll use babynames as an example as it's nice and simple
install.packages('babynames')
Once it's complete, we can get a simple list of the dataset to check it's working:
library(babynames)
babynames::births
You can find more packages to install on the CRAN R project. It's worth giving their documentation a full read before you get started.