CentOSRHEL Based

How To Install R and Rstudio on CentOS Stream 10

Install R and Rstudio on CentOS Stream 10

R and RStudio have become essential tools for data scientists, statisticians, researchers, and analysts worldwide. With the release of CentOS Stream 10, many professionals are looking to set up their data analysis environment on this cutting-edge platform. This comprehensive guide will walk you through the complete process of installing both R and RStudio on CentOS Stream 10, ensuring you have a fully functional environment for your statistical computing and data visualization needs.

Table of Contents

Introduction

R is a powerful programming language specifically designed for statistical computing, data analysis, and graphical representation. It provides a wide range of statistical and graphical techniques, including linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, and clustering. RStudio complements R by providing an integrated development environment (IDE) that makes working with R significantly more productive and user-friendly.

CentOS Stream 10 offers an excellent platform for R programming due to its stability, security features, and enterprise-grade performance. As a rolling-release distribution that tracks just ahead of Red Hat Enterprise Linux, it provides a perfect balance between stability and access to newer software packages.

Whether you’re a data scientist working with large datasets, a researcher analyzing experimental results, or a statistician developing new methodologies, this guide will help you establish a robust R environment on your CentOS Stream 10 system.

Prerequisites and System Requirements

Before beginning the installation process, ensure your system meets the following requirements:

  • A working installation of CentOS Stream 10
  • At least 1GB of RAM (2GB or more is recommended for optimal performance)
  • At least 5GB of free disk space for R, RStudio, and common packages
  • Root access or a user account with sudo privileges
  • Active internet connection for downloading packages
  • Basic familiarity with terminal commands

The hardware requirements for R and RStudio depend largely on the size and complexity of the data you’ll be working with. For basic statistical analysis and learning purposes, modest hardware will suffice. However, for complex modeling or working with large datasets, consider systems with more RAM and processing power.

It’s also helpful to have some terminal/command line experience, though this guide will provide detailed instructions for each step.

Updating Your CentOS Stream 10 System

Before installing any new software, it’s essential to update your existing system packages. This ensures compatibility and helps prevent potential issues during installation.

Open a terminal window and execute the following commands:

sudo dnf upgrade --refresh

This command updates all installed packages to their latest versions and refreshes the repository metadata. The process may take several minutes depending on your internet connection speed and the number of packages that need updating.

After the update completes, it’s a good practice to reboot your system, especially if kernel updates were applied:

sudo shutdown -r now

Once your system restarts, log back in using your user account to continue with the installation process.

Enabling Required Repositories

CentOS Stream 10, like other Enterprise Linux distributions, maintains a conservative approach to software versions in its default repositories. To access the latest version of R and its dependencies, you’ll need to enable additional repositories.

Enabling EPEL Repository

The EPEL (Extra Packages for Enterprise Linux) repository contains many additional packages not available in the standard CentOS repositories, including R and its dependencies.

To enable EPEL on CentOS Stream 10, run:

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm

This command downloads and installs the EPEL repository configuration package for CentOS Stream 10.

Enabling CodeReady Builder (CRB) Repository

The CodeReady Builder repository provides additional development tools and libraries needed for R and some of its packages. To enable the CRB repository, execute:

sudo dnf config-manager --set-enabled crb

This command enables the CRB repository, making its packages available for installation.

Verifying Repository Configuration

To verify that both repositories were successfully enabled, run:

sudo dnf repolist

This command displays a list of enabled repositories. Both EPEL and CRB should appear in the list, confirming they’re properly configured.

Installing R on CentOS Stream 10

With the necessary repositories enabled, you can now install R on your system. There are several installation options available, depending on your specific needs.

Basic R Installation

For a basic installation of R, run:

sudo dnf install R

This command installs the base R package, providing the core functionality needed for statistical computing and analysis.

Installing Development Packages

If you plan to build R packages from source or need development libraries, install the R development package:

sudo dnf install R-devel

Installing Additional R Components

For a more comprehensive installation, you can install additional R components:

sudo dnf install R-core R-core-devel R-java R-devel

This installs the core R packages, development files, and Java support, providing a more complete R environment.

Verifying R Installation

To verify that R was installed successfully, run:

R --version

This should display the installed version of R, confirming that the installation was successful. You can also test R by launching the R console:

R

This will start an interactive R session. Try a simple command such as:

print("Hello, R is working!")

Type q() to exit the R console when finished.

Installing RStudio Desktop (Option 1)

RStudio Desktop provides a user-friendly interface for working with R on your local machine. It’s the preferred option for single-user systems.

Downloading RStudio Desktop

First, you’ll need to download the RStudio package. Visit the official RStudio download page (https://posit.co/download/rstudio-desktop/) and copy the link for the Red Hat/CentOS package.

In your terminal, download the package using wget:

wget https://download1.rstudio.org/electron/rhel9/x86_64/rstudio-2024.12.1-563-x86_64.rpm

Note: The URL may change as new versions are released. Always check the official website for the latest version.

Installing RStudio Desktop

Once downloaded, install RStudio using the dnf package manager:

sudo dnf install ./rstudio-2024.12.1-563-x86_64.rpm

This command installs RStudio Desktop and any dependencies it requires.

Verifying RStudio Desktop Installation

To verify the installation, launch RStudio from your application menu or by typing:

rstudio

The RStudio IDE should open, displaying its four-panel interface. If R was properly installed, RStudio should automatically detect and use it.

Install R and Rstudio on CentOS Stream 10

Installing RStudio Server (Option 2)

RStudio Server provides browser-based access to RStudio, making it ideal for multi-user environments or remote access scenarios.

Understanding RStudio Server Benefits

RStudio Server offers several advantages over the desktop version:

  • Access R and RStudio from any computer using a web browser
  • Centralized installation and management
  • Run resource-intensive computations on a powerful server while accessing from lighter clients
  • Support for multiple concurrent users

Downloading RStudio Server

Download the latest version of RStudio Server:

wget https://download2.rstudio.org/server/centos7/x86_64/rstudio-server-rhel-latest-x86_64.rpm

Note: Check the RStudio download page for the most current version URL.

Installing RStudio Server

Install RStudio Server using dnf:

sudo dnf install ./rstudio-server-rhel-latest-x86_64.rpm

Configuring RStudio Server Service

After installation, the RStudio Server service should start automatically. Verify its status:

sudo systemctl status rstudio-server

If the service isn’t running, start it and enable it to launch at boot:

sudo systemctl start rstudio-server
sudo systemctl enable rstudio-server

By default, RStudio Server runs on port 8787. You can modify this and other settings in the configuration file located at /etc/rstudio/rserver.conf.

Configuring Firewall for RStudio Server

If you’re running RStudio Server and want to access it from other computers, you’ll need to configure the firewall to allow connections to the RStudio Server port.

Opening Firewall Port

Use the following commands to open port 8787 (RStudio Server’s default port) in the firewall:

sudo firewall-cmd --permanent --zone=public --add-port=8787/tcp
sudo firewall-cmd --reload

The first command adds a permanent rule allowing TCP traffic on port 8787, and the second command reloads the firewall configuration to apply the changes.

Verifying Firewall Configuration

To verify that the port is open, run:

sudo firewall-cmd --list-ports

Port 8787/tcp should appear in the list of open ports.

Security Considerations

When exposing services to the network, consider these security measures:

  • Use strong passwords for all system accounts
  • Consider setting up SSL/TLS encryption for RStudio Server
  • Limit access to specific IP addresses if possible
  • Regularly update your system and RStudio Server

Accessing and Using RStudio Server

With RStudio Server installed and the firewall configured, you can now access it through a web browser.

Browser Access

Open a web browser and navigate to:

http://your_server_ip:8787

Replace your_server_ip with your server’s actual IP address or hostname.

Login Procedure

You’ll be presented with a login screen. Enter the username and password of a valid system account on your CentOS Stream 10 server.

First-Time Experience

Upon first login, you’ll see the RStudio IDE interface in your browser. It’s nearly identical to RStudio Desktop, featuring:

  • A source code editor (top-left)
  • A console for executing R commands (bottom-left)
  • Environment/history pane (top-right)
  • Files/plots/packages/help pane (bottom-right)

Take some time to explore the interface and familiarize yourself with its layout and features.

Installing Additional R Packages

One of R’s greatest strengths is its extensive ecosystem of packages. Here’s how to install additional packages for your specific needs.

Using RStudio Package Interface

The easiest way to install packages is through RStudio’s interface:

  1. Click on the “Packages” tab in the bottom-right pane
  2. Click “Install”
  3. Type the name of the package you want to install
  4. Click “Install”

Command Line Package Installation

You can also install packages directly from the R console:

install.packages("package_name")

For example, to install the popular data manipulation package dplyr:

install.packages("dplyr")

Installing Common Essential Packages

Consider installing these essential packages for data science work:

install.packages(c("tidyverse", "data.table", "ggplot2", "shiny", "rmarkdown", "knitr"))

This installs a collection of packages commonly used for data manipulation, visualization, and reporting.

Development Tools for Building Packages

If you plan to build packages from source, install the necessary development tools:

sudo dnf groupinstall "Development Tools"

This installs compilers and other tools needed to build R packages from source code.

Security Best Practices

Maintaining a secure R and RStudio environment is essential, especially in multi-user or server settings.

System Updates

Regularly update your CentOS Stream 10 system to get security patches:

sudo dnf upgrade

Keeping R and RStudio Updated

Periodically check for updates to R and RStudio:

sudo dnf upgrade R rstudio-server

User Account Security

  • Use strong, unique passwords for all user accounts
  • Consider implementing SSH key authentication instead of password login
  • Implement appropriate file permissions for shared R projects and data

Network Security

  • Use a firewall to restrict access to necessary ports only
  • Consider setting up a VPN for remote access
  • For production environments, configure SSL/TLS for encrypted connections to RStudio Server

Troubleshooting Common Installation Issues

Even with careful installation, issues can sometimes arise. Here are solutions to common problems:

Repository Connection Problems

If you encounter errors connecting to repositories, verify your internet connection and DNS settings. You can also try using a different mirror:

sudo dnf --setopt=reposdir=/etc/yum.repos.d clean metadata

Package Dependency Conflicts

If you see dependency conflicts during installation, try:

sudo dnf --best --allowerasing install R

This allows DNF to resolve conflicts by potentially removing problematic packages.

Permission-Related Errors

If you encounter permission errors, ensure you’re using sudo for installation commands. For package installation issues within R, check the write permissions to your R library paths.

Memory Limitation Issues

If R crashes during computation-intensive tasks, you may need to increase available memory:

memory.limit(size=4000)  # Set memory limit to 4GB

Log Files for Debugging

Check these log files for troubleshooting:

  • RStudio Server logs: /var/log/rstudio-server/
  • R installation issues: /var/log/dnf.log

Advanced Configuration Options

For users requiring more customized setups, these advanced configurations may be helpful.

Customizing RStudio Server Settings

Edit the RStudio Server configuration file:

sudo nano /etc/rstudio/rserver.conf

Common settings include:

www-port=8787
auth-required-user-group=rstudio-users
www-thread-pool-size=4

User Permission Management

Create a dedicated group for RStudio users:

sudo groupadd rstudio-users
sudo usermod -aG rstudio-users username

Then configure RStudio Server to only allow access to members of this group.

Resource Allocation Settings

Control memory and CPU usage by editing:

sudo nano /etc/rstudio/rsession.conf

Add settings like:

session-timeout-minutes=30
memory-limit-mb=4096

Custom R Library Paths

To set up a shared library location:

sudo mkdir -p /opt/R/library
sudo chmod 1777 /opt/R/library

Then configure R to use this location by editing .Renviron or .Rprofile files.

Congratulations! You have successfully installed R and Rstudio. Thanks for using this tutorial for installing the R and Rstudio on your CentOS Stream 10 system. For additional help or useful information, we recommend you check the official Rstudio website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button