How To Install R On CentOS 7
This tutorial will teach you how to install R on CentOS 7 and how to install R packages from the official Comprehensive R Archive Network (CRAN) .
Installing R on Centos
At the time of writing the latest stable version of R is version 3.5.
To install R on CentOS 7, follow these steps:
R packages are available in the EPEL repositories. If you don’t have EPEL repository installed on your machine you can do it by typing:
You will be prompted to accept the repository GPG key, type y and hit Enter.
Once the repository is added, install R by typing:
R is a meta package that contains all the necessary R components.
Verify the installation by typing the following command which will print the R version:
Installing R Packages from CRAN
One of the main reasons why R is so popular is the wide array of packages available through the Comprehensive R Archive Network (CRAN).
For demonstration purposes, we’ll install a package named stringr , which provides fast and correct implementations of common string manipulations.
When started as root the packages will be installed globally and available for all system users. If you start R without sudo, a personal library will be set up for your user.
Start by opening the R console as a root:
Install the stringr package by running the following command:
You will be asked to select a CRAN mirror:
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:
Run the following function which will print the length of each string:
You have successfully installed R your CentOS machine and learned how to install R packages.