How to Install R on Ubuntu 24.04 LTS

R is an open-source robust programming language for scientific computing, statistical analysis, and data visualization. R provides a rich set of statistical functions for tasks like regression analysis, data modeling, and hypothesis testing and allows you to create high-quality plots, graphs, and charts. Whether you are exploring data or visualizing results, R programming makes it easy for you to generate compelling results.

Read this tutorial to find different methods of R installation on Ubuntu 24.04. 

Outline:

How to Install R on Ubuntu 24.04

You can install R on Ubuntu 24.04 from:

  • Ubuntu Official Repository
  • CRAN Repository
  • rig Package Manager

How to Install R on Ubuntu 24.04 from the Ubuntu Official Repository

Ubuntu’s official repository includes the core R packages that can be installed directly from the apt command. The method is simple to follow, however, it doesn’t install the up-to-date version of R on Ubuntu. 

You can go through the steps provided below to install R on Ubuntu 24.04 from the official Ubuntu repository:

Step 1: Update Ubuntu Repository

Since we are installing R from the Ubuntu repository, you must update the repository first to ensure up-to-date packages are installed. To update the Ubuntu repository, run the following command:

sudo apt update && sudo apt upgrade -y
Install R on Ubuntu 24.04 LTS a

Step 2: Install R from the Ubuntu Repository

After updating the Ubuntu repository, install R on the system through the below-provided command:

sudo apt install r-base r-base-dev -y
Install R on Ubuntu 24.04 LTS b

In the above command, the r-base package installs the core packages that allow users to run R scripts and work with R packages. The r-base-dev package is an R-based development tool that allows users to compile R packages from the source. 

Step 3: Confirm R Installation

To confirm the R installation on Ubuntu 24.04, use the below-given command:

R --version
Install R on Ubuntu 24.04 LTS c

How to Install R on Ubuntu 24.04 from the CRAN Repository

Another way to install R on Ubuntu 24.04 is from the CRAN (Comprehensive R Archive Network) repository. CRAN is a network of servers that includes the up-to-date version of packages and software, including R. With CRAN, you can install the latest version of R programming language on your system and can update it easily if there is any latest release of R available. 

To install R’s latest version on Ubuntu 24.04 using the CRAN repository, perform the below-given steps:

Step 1: Add GPG Key

First, add the GPG key using the following command to authenticate the CRAN repository addition to the Ubuntu system:

wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc

Step 2: Add CRAN Repository

Once, you added the GPG key, it’s now time to add the CRAN repository to Ubuntu 24.04 from the following command:

sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/"

Press Enter to add the repository and update the Ubuntu repository list. 

Note: Ensure the CRAN repository must be successfully added to the Ubuntu system. 

Step 4: Install Dependencies for R Installation

Before you begin the R installation from the apt command, first install some dependencies on the Ubuntu system from the following command:

sudo apt install libcurl4-openssl-dev libfontconfig1-dev libcairo2-dev libssl-dev libxml2-dev -y

Step 5: Install R on Ubuntu 24.04

After successfully adding the CRAN repository and installing dependencies, it’s time to install R on Ubuntu 24.04 by using the following command:

sudo apt install r-base r-base-dev -y

Step 6: Confirm R Installation

To ensure an up-to-date version of R is installed on Ubuntu 24.04 through the CRAN repository, use the below-given command:

R --version
Install R on Ubuntu 24.04 LTS d

This ensures that R is successfully installed on the Ubuntu system from the CRAN repository.

How to Install R on Ubuntu 24.04 from the rig Package Manager

R Installation Manager, commonly referred to as rig makes it easy for users to install and manage different versions of the R programming language on your system. If you are working on a task that requires a different version of R, this method will be useful in that case. Go through the steps below to install R on Ubuntu 24.04 from the rig package manager:

Step 1: Install curl on Ubuntu

To install rig on Ubuntu, first install the curl command utility on the system from the following command:

sudo apt install curl -y
Install R on Ubuntu 24.04 LTS e

Step 2: Download rig Deb File

Now, navigate to the rig release page on GitHub and download the latest version deb file according to the system architecture. For Ubuntu 24.04, you must download the amd64 deb file, and the latest version of rig at the time of installation was 0.7.0. You can download this version directly on the terminal with the following wget command:

wget https://github.com/r-lib/rig/releases/download/v0.7.0/r-rig_0.7.0-1_amd64.deb
Install R on Ubuntu 24.04 LTS f

Step 3: Install rig on Ubuntu from Deb file

You can now install rig on Ubuntu from the deb file using the apt install command with the deb filename you downloaded earlier:

sudo apt install ./r-rig_0.7.0-1_amd64.deb
Install R on Ubuntu 24.04 LTS g

Step 4: Install R from rig on Ubuntu

You can then install R on Ubuntu from the rig package manager using the following command:

sudo rig add release
Install R on Ubuntu 24.04 LTS h

You can confirm R’s installation on Ubuntu through rig using the following command:

R --version

How to Use R on Ubuntu 24.04

The R programming language requires separate packages for performing specific tasks like machine learning, data visualization, and more. You must install the package according to your task by first running the R interpreter using:

R
Install R on Ubuntu 24.04 LTS i

Then use the following syntax to install the desired package for your task:

install.packages("package_name")

Replace the package_name with the package you want to download for R; here, we are installing ggplot package for data visualization:

install.packages("ggplot2")
Install R on Ubuntu 24.04 LTS j

After installing the package, load the specific package library using:

library(ggplot2)
Install R on Ubuntu 24.04 LTS k

Once the library is loaded, you can use different ggplot datasets to test the features. You can view the list of install datasets that come with this package by using:

data()
Install R on Ubuntu 24.04 LTS l

As an example, we are running the following code that creates a line plot using the BOD dataset, where the X-axis represents time and the Y-axis represents demand:

ggplot(data = BOD, aes(x = Time, y = demand)) + geom_line()
Install R on Ubuntu 24.04 LTS m

How to Remove R from Ubuntu 24.04

Removing R from Ubuntu is simple and can be done using the below-provided command:

sudo apt remove r-base r-base-dev -y
Install R on Ubuntu 24.04 LTS n

Conclusion

R is a versatile programming language that empowers scientific research, data analysis, and visualization on your Ubuntu system. You can install R on Ubuntu 24.04 from the official system repository, CRAN repository, or rig package manager
The method to install R from the official system repository is simple and easy to perform in a single step using the apt install command. For the CRAN repository, you have to manually add the repository and key, then update the repository and install R from the apt command. Alternatively, installing R from the rig package manager won’t be difficult and can be installed after installing the rig from the curl command. You can choose any method for R installation from the above section of this guide according to your choice.