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.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Packages installation queries on Ubuntu Linux Servers.
In this context, we shall look into how to install the R programming language on Linux Ubuntu distribution.
How to install R on Ubuntu 20.04 ?
To begin, Ensure that You should have root or to run sudo command privileges.
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 following steps in order to install R on Ubuntu 20.04 system by using the CRAN repository.
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.
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
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/'
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 R packages will be installed on your system.
4. Check R version
Once the R is installed, type the following command to check the installed version of R programming software:
$ R --version
This will show the version of R installed on your system.
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
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 of using R on Ubuntu:
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:
Now, load the 'txtplot' library by running the following command:
Here, 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 will display a graph on the terminal.
To exit from the R console, type the following command on the terminal:
A prompt will appear for saving the above workspace image.
Press 'y' if you want to save the workspace.