How to Install R on Debian/Ubuntu
This guide explains how to install the R programming language on your Debian or Ubuntu server. R is an open-source language widely used for developing statistical software, data analysis, and visualization.
Order a Server
To run R and your data analyses, HostMyServers offers several options:
- Performance VPS - Ideal for intensive computing
- NVMe VPS - Great value for money
- Eco Dedicated Servers - For large datasets
- Performance Dedicated Servers - Maximum performance for machine learning
Prerequisites
- SSH access as root or user with sudo
- Debian 11/12 or Ubuntu 20.04/22.04/24.04
- Minimum 1 GB RAM (2 GB+ recommended for heavy computations)
Why Use R?
R is particularly suited for:
- Statistical Analysis: Tests, regression models, analysis of variance
- Data Visualization: Publication-ready graphics with ggplot2
- Machine Learning: Classification, clustering, neural networks
- Bioinformatics: Genomic and proteomic analysis
- Finance: Risk analysis, financial modeling
Step 1: Install Dependencies
Since R is an actively developed project, the latest stable version is not always available in Debian/Ubuntu repositories. We will add the external repository maintained by CRAN.
Update the System
sudo apt update && sudo apt upgrade -y
Install Required Tools
sudo apt install -y dirmngr gnupg apt-transport-https ca-certificates software-properties-common
These packages provide:
dirmngr: Certificate management and network operationsgnupg: GPG key managementapt-transport-https: HTTPS support for APTca-certificates: Certificate authority certificatessoftware-properties-common: Repository management
Step 2: Add CRAN Repository
Add the GPG Key
sudo gpg --keyserver keyserver.ubuntu.com --recv-key '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7'
sudo gpg --armor --export '95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7' | sudo tee /etc/apt/trusted.gpg.d/cran_debian_key.asc
Add the Repository for Your Distribution
For Debian 11 (Bullseye)
echo "deb http://cloud.r-project.org/bin/linux/debian bullseye-cran40/" | sudo tee /etc/apt/sources.list.d/r-project.list
For Debian 12 (Bookworm)
echo "deb http://cloud.r-project.org/bin/linux/debian bookworm-cran40/" | sudo tee /etc/apt/sources.list.d/r-project.list
For Ubuntu 22.04 (Jammy)
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/"
For Ubuntu 24.04 (Noble)
sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/"
Update Package List
sudo apt update
Step 3: Install R
Check Available Version
apt-cache policy r-base
Install R
sudo apt install -y r-base r-base-dev
The r-base-dev package includes development tools needed to compile R packages from source.
Verify Installation
R --version
You should see something like:
R version 4.4.x (2024-xx-xx) -- "Pile of Leaves"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu
Step 4: Using R
Launch R in Interactive Mode
For personal use:
R
To install packages available to all users:
sudo -i R
R Interface
Once in R, you will see the > prompt. Here are some basic commands:
# Display version
version
# Get help
help()
# Quit R
q()
Step 5: Install Packages from CRAN
R has thousands of packages available on CRAN (Comprehensive R Archive Network).
Install a Package
In the R interpreter:
install.packages('package_name')