Ubuntu

How to Install R on Ubuntu 20.04

Install R on Ubuntu 20.04

R Programming language is an open-source and free software environment that is specifically used for statistical computing and graphical data representation. R software is specially designed for data miners for developing statistical applications, and statisticians for performing data analysis.

In this article, we will give you a brief demo on how to install the R programming language on Linux Ubuntu distribution. All steps we have executed on Ubuntu 20.04 system in this article. Let’s start the R installation!

Prerequisites

The following requirements should meet for R installation on Ubuntu 20.04 system:

  1. System RAM should have at least 1 GB.
  2. You should have root or to run sudo command privileges.

Installation of R on Ubuntu 20.04

The R packages, available in the default Ubuntu repository are outdated. Therefore, it is the best alternative to install R from the CRAN repository. So, implement the below-mentioned steps in order to install R on Ubuntu 20.04 system by using the CRAN repository:

Step 1: Install Required Dependencies

Launch the terminal by pressing ‘Ctrl + Alt + t’ or open the terminal by clicking on the ‘Activities’ and type terminal in the search bar as follows:

First, install the all required packages that are necessary for adding a new CRAN repository. Execute the following command to install all dependencies:

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

The following output shows on the terminal window:

Step 2: Add Cran Repository

Add the Cran repository by running the following commands in the terminal:

$ 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/'

Step 3: Install R 

Execute the below-given command to install R on your Ubuntu 20.04 system:

$ sudo apt install r-base

When you will run the above command the following R packages installs on your system:

Step 4: Check R version

Once the R is installed, type the following command to check the installed version of R programming software:

$ R --version

From the following output, it is verified that R is installed on your system now.

Step 5: Install essential build packages

R has a variety of packages. Therefore, before starting the compilation process install some essential packages that are required for compiling R programs.

The following command can be used to install the required build packages:

$ sudo apt install build-essential

Step 6: Access R Console

First, type the following command to access the R shell environment where you can install the required R packages:

$ sudo -i R

Now, you can install all R packages on your system.

Example:

In this example, install the ‘txtplot’ package that plots the graph of given values. Install the R package ‘txtplot’ by typing the following terminal command:

> install.packages(“txtplot”)

Now, load the ‘txtplot’ library by running the following command:

> library(“txtplot”)

In this example, we have explained the basic overview of the graph plot between the car acceleration and speed.

> txtplot(cars[,1], cars[,2], xlab = “acceleration”, ylab = “speed”)

The above command displays the following graph on the terminal:

To exit from the R console, type the following command on the terminal:

> q()

The following prompt will appear for saving the above workspace image:

Press ‘y’ if you want to save the workspace.

Conclusion

We have covered all details related to R installation on Ubuntu 20.04 system in this article. We have also given you a brief demo on how you can install R packages and utilize them according to your needs. We have installed a graphical plotting package in this article. You can install more R packages by using the install.packages() command. Thanks for reading this useful article.

Similar Posts