Install R on Rocky Linux 8 & 9 [Step-by-Step]

What is R?

R is a software environment for statistical computing and graphics, as well as a programming language. It is free software supported by the R Foundation and is part of the GNU Bill.

R includes:

Advertisement
  • an effective data handling and storage facility,
  • a suite of operators for calculations on arrays, in particular matrices,
  • a large, coherent, integrated collection of intermediate tools for data analysis,
  • graphical facilities for data analysis and display either on-screen or on hardcopy, and
  • a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities.

With this article, we will explain the installation of the necessary packages for software development with R on Rocky Linux.

 

Steps to install R on Rocky Linux

First of all, let's explain the installation stages of the R version from the Epel repository. Next, let's explain how to install a specific R version.

 

Method-1: Install R From Epel Repository

Step-1: Add EPEL repository

To install the R package, the Rocky Linux Ta Epel repository must be activated.

To add the Epel repository to Rocky Linux 9:

[foc@rocky9 ~]$ sudo dnf -y install epel-release

or

Advertisement
[foc@rocky9 ~]$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

Then the crb repository is enabled:

[foc@rocky9 ~]$ sudo dnf config-manager --set-enabled crb

To add the Epel repository to Rocky Linux 8:

[foc@rockylinux8 ~]$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Then the powertools repository is enabled:

[foc@rockylinux8 ~]$ sudo yum config-manager --set-enabled powertools

 

Step-2: Install the R Package:

To install the R package Rocky Linux 9 the following command is run:

[foc@rocky9 ~]$ sudo dnf -y install R

For Rocky 8

[foc@rocky9 ~]$ sudo yum install R

After these commands, the R package in the repository is installed. Version:

[foc@rocky9 ~]$ 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-2: Download and  Install Specific R version

If there is no compelling reason, the current package version should be installed. Installed version 4.2.1 from Epel repository. You can follow the steps below to install a different version.

Below you can find several versions for R:

  • R 4.2.1 (June, 2022)
  • R 4.2.0 (April, 2022)
  • R 4.1.3 (March, 2022)
  • R 4.1.2 (November, 2021)
  • R 4.1.1 (August, 2021)

Again, as in the previous installation steps, if the Epel repository is not attached, add it:

For Rocky Linux 9:

[foc@rocky9 ~]$ sudo dnf -y install epel-release

or

Advertisement
[foc@rocky9 ~]$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

Then the crb repository is enabled:

[foc@rocky9 ~]$ sudo dnf config-manager --set-enabled crb

For Rocky Linux 8:

[foc@rockylinux8 ~]$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Then the powertools repository is enabled:

[foc@rockylinux8 ~]$ sudo yum config-manager --set-enabled powertools

Type the version you want to load into the R_VERSION environment variable and export it.

[foc@rocky9 ~]$ export R_VERSION=4.2.0

Then pull the .rpm package:

[foc@rocky9 ~]$ sudo curl -O https://cdn.rstudio.com/r/rhel-9/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 67.0M 100 67.0M 0 0 1825k 0 0:00:37 0:00:37 --:--:-- 1853k

".rpm" file downloaded:

Advertisement
[foc@rocky9 ~]$ ls
R-4.2.0-1-1.x86_64.rpm

Install the package:

[foc@rocky9 ~]$ sudo dnf install R-4.2.0-1-1.x86_64.rpm

On Linux systems, 3rd party software is installed under the /opt directory.

[foc@rocky9 ~]$ ls /opt/
R
[foc@rocky9 ~]$ sudo ln -s /opt/R/4.2.0/bin/R /usr/local/bin/R
[foc@rocky9 ~]$ sudo ln -s /opt/R/4.2.0/bin/Rscript /usr/local/bin/Rscript

Check version:

[foc@rocky9 ~]$ R --version
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-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/.

We have successfully installed a specific version.c

 

Using R Programming Language (Example)

You can start writing applications by typing R in the terminal:

Advertisement
[foc@rocky9 ~]$ R

Then you can run R commands in the opened command line:

R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> print('This is first Program')
[1] "This is first Program"

 

Summary

In this article, we have explained the R installation in two different ways. You can apply both methods to the system at the same time and run two different versions on the same server.

For more information on R, run the following command in terminal:

[foc@rocky9 ~]$ R --help

Usage: R [options] [< infile] [> outfile]
   or: R CMD command [arguments]

Start R, a system for statistical computation and graphics, with the
specified options, or invoke an R tool via the 'R CMD' interface.

Options:
  -h, --help            Print short help message and exit
  --version             Print version info and exit
  --encoding=ENC        Specify encoding to be used for stdin
  --encoding ENC
  RHOME			Print path to R home directory and exit
  --save                Do save workspace at the end of the session
  --no-save             Don't save it
  --no-environ          Don't read the site and user environment files
  --no-site-file        Don't read the site-wide Rprofile
  --no-init-file        Don't read the user R profile
  --restore             Do restore previously saved objects at startup
  --no-restore-data     Don't restore previously saved objects
  --no-restore-history  Don't restore the R history file
...

 

References

docs.rstudio.com - RStudio Install R

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X