Install R and RStudio on CentOS 7

R is a free programming environment, mainly used (but not limited to) for statistical analysis. R is maintained by R Foundation. RStudio is a free integrated development environment (IDE) for R programming language.
This guide requires:
  • A CentOS 7 machine.
  • A sudo user, or root user.

StepĀ  0 – Prerequisites

On CentOS 7, R is available to be installed using yum via epel package repository, so we need to add it first.
sudo yum install epel-release
sudo yum update

Step 1 – Install R

sudo yum install R -y

Verify

Let’s run the R console

R console

Step 2 – Install RStudio Server

Can look for the latest available version here.
wget https://download2.rstudio.org/rstudio-server-rhel-1.1.453-x86_64.rpm
sudo yum install rstudio-server-rhel-1.1.453-x86_64.rpm -y

Step 3 – Start and Log-in into RStudio

sudo systemctl status rstudio-server
R status
This will also install a command-line utility ‘rstudio-server‘, can be used to check the status, or any active sessions, and more.
rstudio-server
In case you’re installing it on a server (no GUI), you can use RStudio via browser, by opening the port RStudio is running on (8787 by default). For a GUI machine, just open the RStudio at http://localhost:8787, the following screen will appear, use the username and password you have used for installing the RStudio (sudo user).
RStudio login
Now if we look for active sessions
R active sessions

The RStudio

The dashboard has code editor, debugging and visualization tools.
RStudio homepage

Step 4 – Adding packages from CRAN (Optional)

CRAN stands for Comprehensive R Archive Network, has list of URLs from where R packages can be installed. Available CRAN mirrors.
There are packages which are not entirely written in R, hence may require compilation, for this it is required to install build tools. On CentOS 7 you can do so executing the following single command
sudo yum groupinstall "Development Tools"
It’s a good practice to launch the R console as root user (using sudo) in case of installing a package.
sudo -i R
Once you’re inside the R console, now you can install packages – for demo I’ll be installing ‘txtplot’
install.packages('txtplot')
You”ll be prompted to select the mirror i.e. location you need to download from, the nearer the better, to minimze latency.
R package install

Leave a Reply

Your email address will not be published. Required fields are marked *