How to Install R on Rocky Linux [Step by Step Guide]

How to Install R on Rocky Linux [Step by Step Guide]

In this tutorial, we will learn about How to install R on Rocky Linux using step by step guide. The “R” is a programming language which is widely used for statistical computing and graphics. This tutorial focuses on installing the R package on Rocky Linux 8 and 9. We will first learn about what is R programming language and its usage followed by the different methods to install the R package on Rocky Linux systems. So, let us begin the tutorial.

 

R Overview

“R” is an open source programming language which is extensively used for statistical computing and graphics. The R language was developed by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zeeland. It is a versatile programming language that comes with extensive package ecosystem and community support.  R provides a wide array of statistical techniques and is highly extensible. The R programming language is widely used in the field of

  • Data Analysis and Statistics
  • Data Visualization
  • Machine Learning
  • Bioinformatics
  • Academic Research
  • Financial Analysis
  • Bossiness Analytics

 

How to Install R on Rocky Linux [Step by Step Guide]

Also Read: How to Install GNOME DESKTOP (GUI) on Rocky Linux 8

To harness the power of R programming language, we will install the package in Rocky Linux 8 and 9. The R package can also be installed on other operating systems like Windows, MacOS or any other Linux distribution. We will focus on learning the R package installation procedure on Rocky Linux systems. There are few prerequisite which must be met before installing the R package in Rocky Linux. These are mentioned in next section.

Prerequisite

  • Rocky Linux installed.
  • EPEL Repository installed.
  • sudo/root user privilege required.

 

NOTE:

Follow Install EPEL Repository to install EPEL repository in Rocky Linux Systems.

 

Method-A. Install Using Default Package Manager

Step-1: Enable EPEL Repository

In Rocky Linux 9, dnf is the default package manager which is used to install the packages in the system. We will use dnf package manager to install the R package in the system. Before you install the R package, make sure EPEL repository is already installed and added in the system which was mentioned in the prerequisite section. Next, execute below command to verify epel repository is added. If you see the epel package listed in the command output as highlighted below, it means epel repository is added.

//On Rocky Linux 8
[[email protected] ~]# yum repolist

//On Rocky Linux 9
[[email protected] ~]# dnf repolist
repo id      repo name
appstream    Rocky Linux 9 - AppStream
baseos       Rocky Linux 9 - BaseOS
epel         Extra Packages for Enterprise Linux 9 - x86_64
extras       Rocky Linux 9 - Extras

 

Next,
If you are using Rocky Linux 8 operating system, you have to  enable powertools repository. To do so, execute below command.

[[email protected] ~]# yum config-manager --set-enabled powertools

If you are using Rocky Linux 9 operating system, you have to enable crb repository. To do so, execute below command.

[[email protected] ~]# dnf config-manager --set-enabled crb

 

Step-2: Install R Package

In this step, after enabling the required repositories, install the R package using below command.

//Install on Rocky Linux 8
[[email protected] ~]# yum install R

//Install on Rocky Linux 9
[[email protected] ~]# dnf -y install R

 

Step-3: Verify R Package Installation

In this step, we will verify if R is successfully installed in the system, To do so, execute below command. If the output shows the R version installed in the system, it means R is installed successfully.

[[email protected] ~]# R --version
R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

 

Method-B.  Install using R Rpm File

Step-1: Verify if epel repository is Added

Repeat step-1 from Method-A to configure epel-repository properly.

 

Step-2: Download R RPM

In this step, before downloading the “R” rpm , set the R environment variable “R_VERSION” specifying which R version you want to download. To do so, execute below command. I am installing R version 4.2.0 rpm.

[[email protected] ~]# export R_VERSION=4.2.0

Next, download the “R” rpm using below command.

[[email protected] ~]# curl -O https://cdn.rstudio.com/r/rhel-9/pkgs/R-${R_VERSION}-1-1.x86_64.rpm

If above command is executed successfully, it  will save a “.rpm” file in the current folder as shown below.

[[email protected] ~]# ls
R-4.2.0-1-1.x86_64.rpm

 

Step-3: Install R package using RPM

In this step, once the R rpm file is download, install the R package using the downloaded rpm file. To do so, execute below command.

//Install on Rocky Linux 8
[[email protected] ~]# yum install R-4.2.0-1-1.x86_64.rpm

//Install on Rocky Linux 9
[[email protected] ~]# dnf install R-4.2.0-1-1.x86_64.rpm

 

Step-4: Create Symbolic Link

In this step, we will create a symbolic link which will point to the installed R file. On Linux systems, the third party softwares are installed under path “/opt” as shown below. The R package is also placed in this path as shown below.

[[email protected] ~]# ls /opt/
R

Next, create a symbolic link using below command.

[[email protected] ~]# ln -s /opt/R/4.2.0/bin/R /usr/local/bin/R
[[email protected] ~]# ln -s /opt/R/4.2.0/bin/Rscript /usr/local/bin/Rscript

 

Step-5: Verify R Package Installation

In this step, verify if the R package is installed successfully by executing below command. If the commend output returns the R version, it means R is successfully installed in the system.

[[email protected] ~]# R --version

 

Summary

We have successfully installed the “R” package on Rocky Linux systems using two different methods. We have also learnt about what is R programming language and where it is used.

Leave a Comment