How to Install R on CentOS 8
3 min read
R is an open-source programming language and free environment that specializes in statistical computing and graphical representation. It is supported by the R Foundation for Statistical Computing and mainly used by statisticians and data miners for developing statistical software and performing data analysis.
This article describes how to install R on CentOS 8.
Ensure that you have met the following prerequisites before continuing with this tutorial:
- Your system has at least 1G of RAM. Otherwise, create a swap file .
- You are logged in as a user with sudo privileges .
Installing R on Centos
R packages are not included in CentOS 8 core repositories. We’ll install R from the EPEL repository :
To install R on CentOS 8, follow these steps:
Enable the EPEL and PowerTools repositories:
sudo dnf install epel-release
sudo dnf config-manager --set-enabled PowerTools
Install R by typing:
sudo yum install R
R is a meta-package that contains all the necessary R components.
Verify the installation by printing the R version:
At the time of writing the latest stable version of R is version 3.6.2:
R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night" Copyright (C) 2019 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/.
Install the libraries and tools that are used by common R packages:
sudo yum install make gcc gcc-c++ libcurl-devel libxml2-devel openssl-devel texlive-*
That’s it! You have successfully installed R your CentOS system, and you can start using it.
Installing R Packages from CRAN
One of the main reasons why R is so popular is the vast array of packages available through the Comprehensive R Archive Network (CRAN).
R binary is launched as root or sudo the packages are installed globally and available for all system users. To set up a personal library for your user, invoke the binary as a regular user.
As an example, we’ll install a package named
stringr , which provides fast and correct implementations of common string manipulations.
Start by opening the R console as root:
sudo -i R
R version 3.6.3 (2020-02-29) -- "Holding the Windsock" Copyright (C) 2020 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. >
The commands below are executed within the R console.
You will be asked to select a CRAN mirror:
Installing package into ‘/usr/lib64/R/library’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- Secure CRAN mirrors
Select the mirror that is closest to your location.
The installation will take some time and once completed, load the library by typing:
Next, create a simple character vector named
tutorial <- c("How", "to", "Install", "R", "on", "CentOS", "8")
Run the following function which will print the length of each string:
 3 2 7 1 2 6 1
You can find more R packages at the CRAN Packages page, and install them with
We’ve shown you how to install R on CentOS 8 and how to install R packages.
If you hit a problem or have feedback, leave a comment below.