DEV Community

Tarun Saini
Tarun Saini

Posted on

How to Install R on Ubuntu

The Advanced Packaging Tool (APT) that comes along with Ubuntu uses a file called sources.list to decide where to search for packages.

Before we can install R language, we need to inform Ubuntu to look into the CRAN R repositories and also add a public key for secure download.

  1. Open the sources.list file(usually located at /etc/apt/sources.list) in a text editor and add the following line at the end deb https://<my.favorite.cran.mirror>/bin/linux/ubuntu <distribution>/ For instance, If you are running Ubuntu trusty and want to use the RStudio CRAN mirror, the line would be

deb https://cran.rstudio.com/bin/linux/ubuntu trusty/
If you are lazy like all fineset programmers, you can do this directly from the terminal without having to open a text editor as

sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list'

2.** Authenticate the Ubuntu packages on CRAN**
The packages for Ubuntu that are stored on CRAN mirrors are all signed using a key with ID E084DAB9
We can download the public key from the Ubuntu keyserver using this ID and add it to our system using the command
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

3. Update the list of available packages
Since we modified the sources.list, we need to tell APT to download the packages that are available from the CRAN servers by running the command.
sudo apt-get update

4. Download and install R
Almost done. NOw, Just download and install the R package by running the command:
sudo apt-get -y install r-base
Open up the R console and issue the following command.
$ R
If there were no issues occured during installation. The R console should open successfully with information about your R package installation. You can also learn R via r programming course

Top comments (0)