R is a free and open source programming language that specializes in graphing, reporting, and statistical calculations. It compiles and runs on a wide variety of operating systems such as UNIX, macOS, and Windows. R is supported by the R Foundation for statistical analysis. It is widely used by data miners and statisticians to perform data analysis and develop statistical software.
This article shows you how to install R on CentOS 8 from the command line.
To install R on CentOS 8, you need to make sure that your system RAM has at least 1GB of space.
You need to follow the steps below to start the installation of ‘R’ on your system from the terminal:
If you log in as the root user, you must have sudo command permission to install packages on your system.
Open the terminal application using the shortcut method ‘Ctrl + Alt + t’. Or you can open the terminal by clicking on “Activities”.
Installation of R on CentOS 8
The R packages are not in the CentOS 8 core repositories. You need to install R from the EPEL repository. To enable the epel repository and configuration management power tools, use the following command on the terminal:
$ sudo dnf install epel-release
$ sudo dnf config-manager --set-enabled PowerTools
A user prompt will appear on the screen during the installation. You will press ‘y’ and then ‘Enter’ to proceed with the installation of epel-release.
After a while, the terminal will show a full status indicating that the installation is complete.
Now activate the required power tools on your system for installation.
Install R on CentOS 8
Now that you’ve successfully activated the repositories and power tools, it’s time to install R on your system. Now install R with the package manager ‘yum’ on your CentOS 8. To do this, run the following command in the terminal window:advertising
$ sudo yum install R
Here R denotes a metapackage. All the necessary R components are contained in the metapackage mentioned above.
During the installation of R on CentOS 8, a user confirmation prompt will appear on your system asking you to confirm the installation of the remaining packages. You press ‘y’ and then ‘Enter’ to continue installing more R packages on your system.
A confirmation prompt is displayed again on the terminal asking for confirmation of the import of the GPG key for the installation of R. Enter ‘y’ then ‘Enter’ to continue the installation process.
After the successful installation of all R components, the status ‘Complete’ appears on the terminal, which indicates that R has been successfully installed on your system.
Check the installation of R
You can verify the installation of R on your system by using the following command on the terminal:
In the screenshot above, you can see that R has been successfully installed on your system. At the time of this writing, version 3.6.3 is the latest stable version of R that is available.
Install R build tools and libraries
You must install the supporting libraries and tools on your system that are required for R packages. Use the following command to install the required tools and libraries:
During the installation you will be asked to confirm the installation. You press ‘y’ then press ‘Enter’ to continue installing the required tools and libraries.
When all the libraries and tools are installed on your system, the terminal will show the status ‘Complete’, which means the installation is complete.
Open the R console as root
Now starting with R, open the R console on the terminal as root. Use the following command to open R:
If you start the R binary as root, the packages are installed globally and are available to all users of the system. You can set up a personal library to use and access the R binary as a normal user.
Now all of the below mentioned commands will be executed in the R console.
There is a huge selection of packages available in R that can be installed over the Comprehensive R Archive Network (CRAN).
For example, you might want to install a package from R known as ‘stringr’, which is widely used for the correct and quick implementation of string manipulations.
Install stringr in the R console through the terminal. Enter the following command to install the Stringr package:
After executing the above command, a list of CRAN mirrors appears on the terminal, prompting you to select a CRAN mirror to use.
Now choose the mirror that is closest to your location. For example Mexico City is closest to your location, then enter its number in the selection ’39’.
The installation will take some time. Once the installation is now complete, load the library using the following command in the terminal window:
Now create a vector named article using the following syntax:
> article <- c(“Article”, “About”, "How", "to", "Install", "R", "on", "CentOS", "8")
Use the following function to get the length of each string:
Now you can close the R console by typing the following command on the terminal:
In this article you learned how to install R on CentOS 8 using the terminal. You also learned how to install various R packages on your system. Hope you enjoyed and found this article useful. Please give us your feedback via comments.