How to Install R on Ubuntu 24.04
Step-by-step guide to install R on Ubuntu 24.04 LTS from the official CRAN repository, configure build toolchains, and install statistical packages.

5 min read
Step-by-step guide to install R on Ubuntu 24.04 LTS from the official CRAN repository, configure build toolchains, and install statistical packages.
- Prerequisites and Supported Releases
- Step 1: Installing Prerequisites and Transport Utilities
- Step 2: Adding the Official CRAN GPG Repository Key
Exploratory data analysis, statistical modeling, econometric forecasting, and genomic computation require specialized software environments engineered for matrix algebra and statistical data structures. When you install r on ubuntu 24.04, you deploy an extensible data science runtime supported by thousands of specialized packages hosted across the Comprehensive R Archive Network (CRAN) and Bioconductor ecosystems.
While Ubuntu's upstream universe repositories contain pre-packaged builds of R, distribution packages frequently lag behind major upstream releases. Configuring the official CRAN repository on Ubuntu 24.04 ensures that you always have access to the latest stable R release (R 4.4.x or newer) with immediate security updates, modernized glibc runtime linking, and seamless compatibility with modern CRAN package binaries.
In addition to command-line statistical scripting, R serves as the computational foundation behind graphical IDEs like RStudio, automated report generation with Quarto and R Markdown, and interactive web application dashboards powered by R Shiny.
In this guide, you will learn how to configure CRAN's cryptographic signing keys, register the official Ubuntu 24.04 repository, install the core runtime (r-base) and compilation headers (r-base-dev), install native C/C++ dependencies for external libraries, compile data science packages like tidyverse, and test data frame transformations.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A desktop or server running Ubuntu 24.04 LTS (64-bit architecture).
- A user account with active sudo administrative privileges.
- Access to a command-line terminal and active Internet connectivity.
- At least 4 GB RAM recommended if compiling large statistical packages from source.
Step 1: Installing Prerequisites and Transport Utilities
Before configuring external package repositories, ensure that your system has the necessary security and networking utilities installed. You will need dirmngr, ca-certificates, curl, and gnupg to securely fetch and manage GPG keyrings over HTTPS.
Refresh your APT package database and install these foundational utilities.
Having these security utilities in place guarantees that repository signature handshakes complete reliably without certificate trust errors.
# Refresh package repository index
sudo apt update && sudo apt upgrade -y
# Install networking, certificate, and key management tools
sudo apt install -y dirmngr ca-certificates software-properties-common curl gnupg
Step 2: Adding the Official CRAN GPG Repository Key
In alignment with Ubuntu 24.04 security standards, external repository signing keys must reside in /etc/apt/keyrings/ with restricted permissions, rather than being added to the deprecated legacy global keyring.
Download CRAN's official signing key (authored by Dirk Eddelbuettel / Michael Rutter), de-armor it, and store it in /etc/apt/keyrings/cran.gpg.
Ensure read-only permissions are assigned so that non-root processes cannot tamper with cryptographic certificates.
# Create keyrings directory if it does not already exist
sudo install -m 0755 -d /etc/apt/keyrings
# Download and de-armor CRAN GPG signing key
curl -fsSL https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo gpg --dearmor -o /etc/apt/keyrings/cran.gpg
sudo chmod a+r /etc/apt/keyrings/cran.gpg
Step 3: Registering the Official CRAN APT Repository
Create a dedicated source list entry at /etc/apt/sources.list.d/cran.list that points to the official CRAN distribution mirror for Ubuntu 24.04 (Noble Numbat).
The repository line explicitly references the GPG key via the signed-by attribute to prevent repository spoofing.
After creating the file, refresh your APT package cache to index the newly registered CRAN packages.
# Add CRAN repository source entry
echo "deb [signed-by=/etc/apt/keyrings/cran.gpg] https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/" | sudo tee /etc/apt/sources.list.d/cran.list
# Update package index to register CRAN packages
sudo apt update
Step 4: Installing R Base and Development Toolchains
Install both the core R execution engine (r-base) and the development package (r-base-dev). The r-base-dev package bundles C, C++, and Fortran compilers, Make toolchains, and development headers required whenever you compile CRAN packages containing native code.
Execute the following installation command via APT to deploy both packages simultaneously.
# Install R base and development packages
sudo apt install -y r-base r-base-dev
Step 5: Verifying R Installation and Launching the Console
Verify that the R binary is installed and displays the latest release version.
You can launch the interactive R command-line prompt directly from your terminal by typing R.
Inside the interactive prompt, you can run mathematical expressions, load libraries, and inspect session configurations.
# Verify installed R version
R --version
# Launch interactive R console (type q() to exit)
R
Step 6: Installing System-Level C/C++ Libraries for CRAN Packages
Popular R data science packages like tidyverse, curl, httr, xml2, and sf depend on underlying Linux C/C++ system libraries. If these system headers are missing, running install.packages() inside R will fail during compilation.
Install the essential system-level development libraries prior to installing R packages.
These libraries provide font rendering engines, image decompression formats, and OpenSSL cryptographic hooks.
# Install system libraries required by Tidyverse and data packages
sudo apt install -y build-essential libcurl4-openssl-dev libssl-dev \
libxml2-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev \
libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev
Step 7: Installing Data Science Packages (Tidyverse, ggplot2)
Launch an administrative or user R session to install packages from CRAN. To install packages system-wide so all users have access, launch R with sudo -i R.
Install tidyverse (which bundles dplyr, ggplot2, tidyr, readr, and purrr), specifying the official secure CRAN repository mirror.
# Execute inside the interactive R console
install.packages(c("tidyverse", "ggplot2", "devtools"), repos = "https://cloud.r-project.org/")
Step 8: Executing a Verification Statistical Script
Confirm that R operates properly by writing and executing a non-interactive R script from the command line that creates a data frame, calculates summary statistics, and fits a linear regression model.
Create a script verify_r.R and execute it using Rscript.
The script produces numerical summaries and verifies that statistical functions calculate without error.
# Create verification R script
cat << 'EOF' > verify_r.R
# Generate synthetic data
set.seed(42)
x <- rnorm(100, mean = 50, sd = 10)
y <- 2.5 * x + rnorm(100, mean = 0, sd = 5)
data <- data.frame(Feature = x, Target = y)
# Fit linear regression model
model <- lm(Target ~ Feature, data = data)
cat("=== R STATISTICAL EXECUTION VERIFIED ===
")
cat("Sample Mean of Feature:", mean(data$Feature), "
")
cat("Sample Mean of Target:", mean(data$Target), "
")
cat("
Linear Model Summary:
")
print(summary(model)$coefficients)
EOF
# Execute script using Rscript CLI
Rscript verify_r.R
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
install.packages() fails with 'configuration failed for package libcurl/openssl'
Resolution: This indicates missing Linux development headers. Exit R and install system packages: sudo apt install -y libcurl4-openssl-dev libssl-dev libxml2-dev before retrying the R package installation.
APT update warning: 'The following signatures couldn't be verified because the public key is not available'
Resolution: Re-download and de-armor the CRAN GPG signing key into /etc/apt/keyrings/cran.gpg and verify that /etc/apt/sources.list.d/cran.list includes signed-by=/etc/apt/keyrings/cran.gpg.
Warning: 'unable to create temporary directory' or disk full during package compilation
Resolution: Compiling large C++ packages like Rcpp or arrow creates extensive build artifacts in /tmp. Ensure you have at least 2 GB of free disk space on /tmp.
Security Best Practices and Hardening
Always configure secure HTTPS CRAN mirrors (https://cloud.r-project.org/) to prevent package tampering during download.
Verify that downloaded GPG keys are stored with read-only permissions (0644) in /etc/apt/keyrings/.
Avoid installing unverified packages directly from personal third-party Git repositories without auditing source code.
Run interactive data analysis scripts under an unprivileged user account rather than root.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
- How to Install Anaconda Python on Ubuntu 24.04 — Explore Python data science environments alongside your R installation.
- How to Install and Configure PostgreSQL on Ubuntu 24.04 — Connect R to production relational databases using RPostgreSQL and DBI.
- Things to Do After Installing Ubuntu 24.04 LTS — Post-installation developer toolchain setup and system optimizations.
Authoritative References and Official Documentation
Frequently Asked Questions
Quick answers to common questions and configurations
.deb package from Posit (https://posit.co/download/rstudio-desktop/) and install it via sudo apt install ./rstudio-*.deb.~/R/x86_64-pc-linux-gnu-library/<R-version>/, while system-wide packages are installed in /usr/local/lib/R/site-library.q() and press Enter. When prompted whether to save the workspace image, type n (for no) or y (for yes).Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides











Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!