R is a free and open-source programming language that specializes in graphical representation, reporting, and statistical computing. It compiles and executes on a variety of operating systems like UNIX, MacOS, and Windows. R is supported by R Foundation for statistical analysis. It is commonly used by data miners and statisticians for performing data analysis and developing statistical software.

In this article, you will learn how you can install R on CentOS 8 using the command line.

Pre-requisites

To install R on CentOS 8, you must ensure that your system RAM has at least 1G space.

You need to perform the following steps to start the installation of ‘R’ on your system using the terminal:

Log in as the root user means you must have ‘sudo’ command privileges to install packages on your system.

  1. CentOS Terminal
    Open the terminal application through the shortcut method ‘Ctrl + Alt + t’. Or you can also open the terminal by clicking on the ‘Activities’.

Installation of R on CentOS 8

The R packages are not incorporated in the core repositories of CentOS 8. You need to install R through the EPEL repository. To enable epel repository and configuration management power tools, you will use the following command on the terminal:

$ sudo dnf install epel-release
$ sudo dnf config-manager --set-enabled PowerTools

Add Epel Repository

During the installation, a user prompt will display on the screen. You will press ‘y’ and then ‘Enter’ to further proceed with the installation of epel- release.

Confirm installation

Installation complete
In a while, a complete status will appear on the terminal that indicates the installation has been completed.

Now, you will enable the necessary power tools on your system for installation.

Enable PowerTools

Install R on CentOS 8

After successfully enabling the repositories and power tools, it’s time to install R on your system. Now, you will install R using the ‘yum’ package manager on your CentOS 8. For that purpose, execute the following command on the terminal window:

$ sudo yum install R

Install R programming language package

Here, R indicates a meta-package. All necessary R components are included in above-mentioned meta- package.

Installing dependencies

During the installation of R on CentOS 8, a user confirmation prompt would display on your system that would ask to confirm the installation of the remaining packages. You will press ‘y’ and then ‘Enter’ key to continue the installation of more R packages on your system.

Confirm installation

Again confirmation prompt will display on the terminal that will ask about the confirmation of import GPG key for the installation of R. Type ‘y’ and then ‘Enter’ to continue the installation process.

Accept Epel repository key

After the successful installation of all R components, A ‘Complete’ status would appear on the terminal that will show R has been successfully installed on your system.

Package installation complete

Verify the installation of R

You can verify the installation of R on your system by using the following command on the terminal:

Check which version of R is installed

You can see in the above display screenshot that R has been successfully installed on your system. At the time of writing this article, version 3.6.3 is the latest stable version of R available.

Install R build tools and libraries

You need to install the supportive libraries and tools on your system that are necessary for R packages. Use the following command to install the necessary tools and libraries:

Installing build tools

During the installation, it will ask you about the confirmation for installation. You will press ‘y’ and then hit ‘Enter’ to further continue the installation of necessary tools and libraries.

Confirm installation

When all libraries and tools will be installed on your system, A ‘Complete’ status will display on the terminal that means installation has been completed.

Installation complete

Open R console as root

Now, you will start with R, open the R console on the terminal as root. Use the following command to open R:

R programming Console

If you will launch the R binary as root, then the packages will install globally and available for all users of the system. You can set up a personal library for use, invoke the R binary as a regular user.

Now all below-mentioned commands will run within the R console.

Install stringr

In the R, a huge array of packages are available that can be installed using the Comprehensive R Archive Network (CRAN).

For example, you want to install a package of R known as ‘stringr’ which is commonly used for correct and fast implementations of string manipulations.

Install stringr within the R console through the terminal. Type the following command to install stringr package:

> install.packages("stringr")

After executing the above-given command, a list of CRAN mirrors will appear on the terminal that will be asked to select a CRAN mirror for use.

Installing Stringr library

Now, you will select the closest mirror to your location. For example, Mexico City is closest to your location then enter its number in the selection ‘39’.

Choose download mirror

The installation will take some time for completion. Once the installation is completed now, you will load the library by using the following command on the terminal window:

> library(stringr)

Load stringr library in R

Now, you will create a vector named with article using the following syntax:

> article <- c(“Article”, “About”, "How", "to", "Install", "R", "on", "CentOS", "8")

Using stringr library

Use the following function to print the length of each string:

> str_length(article)

print string lengths

Now you can close the R console by typing the following command on the terminal:

> q()

Close R prompt

Conclusion

In this article, you have learned how to install R on CentOS 8 using the terminal. You have also learned how you can install various R packages on your system. I hope you have enjoyed this article and useful for you. Please give us your feedback via comments.

How to Install and Use R Programming Language on CentOS 8
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn