R is an open source programming language that is used for statistical computing as well as data visualization & is used extensively for the development of software using statistics & performing data analysis. R also provides extensible R packages (more than 10,000) which can be accessed through CRAN or Comprehensive R Archive Network. These R packages can be for specialized computational tools, publication quality figures etc.

Recommended Read : Important PostgreSQL commands you should know

Also Read : Easy guide for Securing Redis Server

In this tutorial, we will learn to install R on Ubuntu & will also see, how we can install R packages from CRAN.


Install R on Ubuntu

As the first step, we will add CRAN repo to our Ubuntu repo list. To do that, open terminal & then open “/etc/apt/sources.list”,

$ sudo nano /etc/apt/sources.list

& add the following line to the end of the file,

For Ubuntu 16.04

deb http://cran.rstudio.com/bin/linux/ubuntu xenial/

Save the file & exit. Now we need to add GPG key for CRAN, to do that run the following command from the terminal,

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

For Ubuntu 18.04, to add the repository we need to run the following command from the terminal,

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

To add the GPG key, execute the following command,

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

Now, we can install R on Ubuntu with the following command,

$ sudo apt-get update

$ sudo apt-get install r-base

That’s it, we now have R installed on our Ubuntu system. 


Install R packages from CRAN

To install the R packages from CRAN, we need to first open the R interpreter, which can be opened using the terminal. Open terminal & type,

$ R

Now let’s say we need to install an R package by the name “av” (which is used for working with audio & video), so we need run the following command from R interpreter,

> install.packages("av")

Next, you will be asked to choose a mirror from a list of mirrors to install the package. Choose one closest to you by typing the corresponding number & package will then be installed. 

To exit from the interpreter, type,

> q()

You will then be asked to save your workspace, which you can do by typing ‘y’ key. That’s it guys, we now conclude our tutorial on how to install R on Ubuntu.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of your hard earned money: [paypal-donation]

Linux TechLab is thankful for your continued support.