Installing R on Ubuntu gives you a reproducible environment for statistics, data analysis, visualization, bioinformatics, machine learning, and research reports without leaving the APT package workflow. The best install path depends on your Ubuntu release: Ubuntu 26.04 currently installs R from the Ubuntu archive, while Ubuntu 24.04 and 22.04 can use the CRAN APT repository for newer upstream builds.
The workflow below installs R, confirms that R and Rscript work, adds CRAN where supported, enables r2u for prebuilt CRAN packages, and removes R cleanly when you no longer need it. It also explains when to use user-level install.packages() instead of system-wide r-cran-* packages.
Install R on Ubuntu: Choose a Method
Choose one base R installation method first, then add r2u only if you want prebuilt CRAN packages through APT. The CRAN APT repository is the best path on supported releases where CRAN publishes packages, but it has not published an Ubuntu 26.04 repository yet, so Ubuntu 26.04 users should start with the Ubuntu archive unless they need a source build.
| Method | Supported Ubuntu Releases | Best For |
|---|---|---|
| Ubuntu Repository | Ubuntu 26.04, 24.04, and 22.04 | Fastest supported install, especially on Ubuntu 26.04 where CRAN has not published a repository yet |
| CRAN APT Repository | Ubuntu 24.04 and 22.04 | Newer CRAN-maintained R packages through normal APT updates |
| r2u (CRAN-Apt) package repository | Ubuntu 26.04, 24.04, and 22.04 on amd64; Ubuntu 26.04 and 24.04 on arm64 | Prebuilt CRAN and Bioconductor packages after R is already installed |
| Manual Source Build | Any release with the required build dependencies | Power users who need custom compiler flags, patched builds, or current source releases before APT packages catch up |
For Ubuntu 24.04 and 22.04, the CRAN APT repository is usually the best choice because it provides newer R builds than the Ubuntu archive while still using APT. For Ubuntu 26.04, use the Ubuntu repository method below until CRAN publishes a native 26.04 repository.
If you searched for an R download for Ubuntu, use the APT methods below instead of hunting for a standalone installer. APT downloads R from Ubuntu or CRAN, tracks dependencies, and gives you normal update and removal behavior.
The active support scope is Ubuntu 26.04, 24.04, and 22.04. As of April 2026, CRAN publishes
noble-cran40andjammy-cran40, whileresolute-cran40is not available. r2u publishes repositories for all three supported LTS releases.
Prepare Ubuntu for R Installation
Refresh Package Indexes and Update Installed Software
Before installing R on Ubuntu, update your package indexes and apply available package updates:
sudo apt update && sudo apt upgrade
These commands require sudo privileges. If your account cannot run administrative commands, review how to add a user to sudoers on Ubuntu before continuing.
Install Repository Tools
Install the helper tools used by the repository commands in this guide. curl downloads signing keys, gpg converts them into APT keyrings, and lsb-release detects your Ubuntu codename:
sudo apt install --no-install-recommends ca-certificates curl gpg lsb-release
Modern Ubuntu releases use the DEB822
.sourcesformat for repository configuration. The commands below create.sourcesentries that align with Ubuntu’s standard approach, even if older tools still emit legacy.listfiles.
Install R from Ubuntu Repository
The Ubuntu repository method works on Ubuntu 26.04, 24.04, and 22.04 without adding an external source. It is the correct starting point for Ubuntu 26.04 because CRAN has not published a native 26.04 repository yet.
R packages are in Ubuntu’s
universecomponent. Ifaptcannot locater-base, enable Universe first with our Ubuntu Universe and Multiverse guide, then rerun the install command.
sudo apt install r-base
Install the development package as well if you plan to compile R packages that need headers, compilers, or native extensions:
sudo apt install r-base-dev
As of April 2026, Ubuntu 26.04 installs R 4.5.2 from the Ubuntu archive. Ubuntu 24.04 and 22.04 also provide R from Universe, but the CRAN repository below currently supplies newer R 4.5.3 builds on those releases.
Add CRAN APT Repository on Ubuntu 24.04 or 22.04
Use this CRAN repository method on Ubuntu 24.04 or 22.04 when you want the newer CRAN-maintained R build. Skip this section on Ubuntu 26.04 until CRAN publishes a resolute-cran40 repository.
Download CRAN Repository Signing Key
Download and convert the signing key maintained by Michael Rutter. Since the published key is ASCII-armored, use curl to fetch it and pipe the output through gpg --dearmor to create the binary format APT requires:
curl -fsSL https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/cran.gpg
The fingerprint of this key is E298 A3A8 25C0 D65D FD57 CBB6 5171 6619 E084 DAB9, matching the CRAN documentation. Next, verify the downloaded key fingerprint matches:
gpg --show-keys --with-fingerprint /usr/share/keyrings/cran.gpg
The output displays the key details you should verify against CRAN’s published fingerprint:
pub rsa2048 2010-10-19 [SCA] [expires: 2027-09-30]
E298 A3A8 25C0 D65D FD57 CBB6 5171 6619 E084 DAB9
uid Michael Rutter <marutter@gmail.com>
sub rsa2048 2010-10-19 [E] [expires: 2027-09-30]
Carefully compare the displayed fingerprint (E298 A3A8 25C0 D65D FD57 CBB6 5171 6619 E084 DAB9) against the published key ID on the CRAN Ubuntu repository page to confirm authenticity. The key should match Michael Rutter’s signing key, which CRAN uses for Ubuntu repository releases.
Add the CRAN Repository
With the key in place, create a DEB822 .sources file for your Ubuntu release. Because CRAN uses a flat repository structure (no dists/ hierarchy), the Suites: line includes the codename path with a trailing slash and Components: remains empty:
printf '%s\n' \
"X-Repolib-Name: CRAN" \
"Types: deb" \
"URIs: https://cloud.r-project.org/bin/linux/ubuntu/" \
"Suites: $(lsb_release -cs)-cran40/" \
"Components:" \
"Signed-By: /usr/share/keyrings/cran.gpg" \
| sudo tee /etc/apt/sources.list.d/cran.sources > /dev/null
The -cran40 suffix indicates the ABI break introduced with R 4.0. It does not mean you are installing R 4.0; current CRAN metadata selects R 4.5.3 on Ubuntu 24.04 and 22.04.
Refresh Package Index
After adding the CRAN repository, refresh your package index so Ubuntu recognizes the new source. Confirm the CRAN repository appears in the output:
sudo apt update
Look for a line similar to Get:X https://cloud.r-project.org/bin/linux/ubuntu/noble-cran40 or Get:X https://cloud.r-project.org/bin/linux/ubuntu/jammy-cran40, depending on your release codename. If you see a 404 for resolute-cran40, remove the CRAN source and use the Ubuntu repository method instead.
Install R from Selected APT Source
Core R Installation
If you already used the Ubuntu repository method above, R is installed and you can continue to verification. If you added the CRAN repository on Ubuntu 24.04 or 22.04, run the same install command now so APT selects the CRAN candidate:
sudo apt install r-base
Install R Development Tools (Optional)
Power users who routinely compile CRAN packages from source should also install r-base-dev to pull in headers, compilers, and documentation:
sudo apt install r-base-dev
Verify the R Installation
Confirm the installation by checking the R version and build information:
R --version
The exact version depends on the method and release. On Ubuntu 24.04 and 22.04 with CRAN enabled, current APT metadata selects R 4.5.3:
R version 4.5.3 (2026-03-11) -- "Reassured Reassurer" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under the terms of the GNU General Public License versions 2 or 3. For more information about these matters see https://www.gnu.org/licenses/.
Rscript is installed with the R base package, so there is no separate rscript package to install. Verify it with:
Rscript --version
Rscript (R) version 4.5.3 (2026-03-11)
Manage Multiple R Versions (Optional)
APT installs R to /usr/bin/R and upgrades that binary in place. If you need multiple R versions for package compatibility testing or reproducibility research, compile from source with a custom --prefix such as --prefix=/usr/local/R/4.6.0, then create shell aliases or environment modules to switch between versions:
# Example: Install R 4.6.0 to /usr/local/R/4.6.0
./configure --prefix=/usr/local/R/4.6.0 --enable-R-shlib
make -j$(nproc)
sudo make install
# Create alias to access this version
echo "alias R-4.6.0='/usr/local/R/4.6.0/bin/R'" >> ~/.bashrc
source ~/.bashrc
This approach lets package maintainers test across R versions without affecting the system installation. For team environments, environment modules or containers are usually easier to audit than shell aliases on each account.
Optional Development Libraries for Package Compilation
Install Recommended R Package Collection
r-recommended installs a curated set of R packages used in data analysis and statistical modeling:
sudo apt install r-recommended
Install SSL Support for CRAN Packages
CRAN packages such as httr need OpenSSL headers during compilation. Install them with:
sudo apt install libssl-dev
Add XML Parsing Capability
For CRAN packages that parse XML, install libxml2-dev. Packages such as XML use this library during compilation:
sudo apt install libxml2-dev
Enable CURL Support in R
For CRAN packages that need CURL support, such as the curl package, install libcurl4-openssl-dev:
sudo apt install libcurl4-openssl-dev
These development libraries let R packages build extensions for SSL connections, XML parsing, and HTTP requests, which are dependencies required by popular packages like httr, XML, and curl.
Understand R Package Management
Console Installation vs System Package Management
R packages can be installed two ways: from the R console using install.packages(), or system-wide through APT using r-cran-* packages. Console installation downloads packages into your home directory (~/.R/library/) and works for individual users without sudo privileges. In contrast, system packages install to /usr/lib/R/library/ and require sudo, making them available to all users on the system.
When to Use Each Method
Use console installation (install.packages()) for personal projects, testing packages, or when you need the latest CRAN release immediately. Alternatively, use APT packages (sudo apt install r-cran-*) for shared servers, reproducible deployments, or when you need Ubuntu’s dependency tracking for system libraries like database connectors or SSL support.
CRAN vs r2u Binary Packages
The r2u project (covered later in this guide) bridges these approaches by converting CRAN packages into Ubuntu packages automatically. This gives you the latest CRAN versions with APT’s dependency management, eliminating compilation time for complex packages like tidyverse or rstan.
Install R Packages via CRAN
Launch the R Interpreter
With R installed on your Ubuntu system, you can now install R packages from the Comprehensive R Archive Network (CRAN). To start the R console, open your terminal and run:
R
This launches the R interactive console. For most users, this user-level approach is preferred. However, if you need to install packages system-wide, you can run sudo -i R, but this is only recommended for shared systems where all users need access to the same packages.
Running R with
sudo -i Rgives package installation root privileges, which is risky for untrusted packages. For personal projects, useRas a regular user instead so your package library stays in your home directory.
Install R Packages
Inside the R console, use install.packages() to add packages to your user library. For example, install ggplot2 and tidyr with:
install.packages(c("ggplot2", "tidyr"))
R will download the packages and their dependencies from CRAN, compile them if necessary, and install them to your library directory. This process may take several minutes depending on package complexity and your system performance.
Search for CRAN Packages
To inspect packages available from CRAN inside R, run:
available.packages()
This returns available package names and descriptions from your configured CRAN mirror. You can also browse the CRAN website directly to search packages by category or topic.
Update Installed R Packages
To update installed packages from the R console without approving each package one by one, run:
update.packages(ask = FALSE)
This updates packages in the active R library without repeated prompts.
Remove R Packages
To remove a package from the active R library, use remove.packages(). For example, remove dplyr with:
remove.packages("dplyr")
This keeps personal project libraries small and avoids removing packages needed by another user or shared project.
Manage System-Wide R Packages with r2u (CRAN-Apt)
The default CRAN package workflow downloads source archives when you run install.packages(), then compiles packages locally when binaries are not available. For workflows requiring hundreds of packages, such as tidyverse, Bioconductor, or machine learning stacks, compilation can take a long time and fail when system dependencies are missing. Install R first with the Ubuntu repository or CRAN APT repository, then enable r2u to pull prebuilt CRAN packages as Ubuntu binaries with automatic dependency resolution through APT.
Building large CRAN stacks from source can be slow and error-prone when system dependencies are missing. r2u avoids most local compilation by shipping prebuilt binaries, which is especially helpful for containers, CI/CD pipelines, and shared servers.
Add the r2u Binary Repository (.sources)
r2u is an APT repository, not a package installed with sudo apt install r2u. First, import the CRAN-Apt (r2u) signing key and verify its fingerprint:
curl -fsSL https://eddelbuettel.github.io/r2u/assets/dirk_eddelbuettel_key.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/cranapt.gpg
Confirm the key matches the published fingerprint before trusting it:
gpg --show-keys --with-fingerprint /usr/share/keyrings/cranapt.gpg
The output should display the fingerprint AE89 DB0E E10E 60C0 1100 A8F2 A148 9FE2 AB99 A21A matching Dirk Eddelbuettel’s key as documented on the r2u GitHub page.
With the key verified, add the r2u .sources file and refresh the package index:
printf '%s\n' \
"X-Repolib-Name: CRAN-Apt Packages" \
"Types: deb" \
"URIs: https://r2u.stat.illinois.edu/ubuntu" \
"Suites: $(lsb_release -cs)" \
"Components: main" \
"Signed-By: /usr/share/keyrings/cranapt.gpg" \
| sudo tee /etc/apt/sources.list.d/cranapt.sources > /dev/null
sudo apt update
r2u publishes amd64 repositories for Ubuntu 26.04, 24.04, and 22.04. Ubuntu 26.04 and 24.04 also receive arm64 builds. The repository syncs with CRAN frequently, so package updates appear quickly after upstream releases.
Do not pair r2u with a source-only R installation. r2u packages depend on APT’s
r-base-corepackage, so installingr-cran-*packages from r2u can pull an APT-managed R stack even if you compiled a separate R binary under/usr/local.
Prioritize r2u Packages with apt Pinning (Optional)
Optionally, assigning a higher priority to the CRAN-Apt release prevents Ubuntu’s older r-cran-* builds from overriding r2u packages:
printf '%s\n' \
"Package: *" \
"Pin: release o=CRAN-Apt Project, l=CRAN-Apt Packages" \
"Pin-Priority: 700" \
| sudo tee /etc/apt/preferences.d/99cranapt > /dev/null
Install Packages via apt or bspm
Once r2u is active, install CRAN packages through APT with their r-cran-* package names. The example below uses jsonlite, a small package that validates the repository path; larger stacks such as r-cran-tidyverse use the same pattern:
sudo apt install r-cran-jsonlite
To let install.packages() call APT automatically, enable the bspm helper package from r2u:
sudo apt install python3-{dbus,gi,apt} make r-cran-bspm
RPROFILE="$(R RHOME)/etc/Rprofile.site"
grep -qxF 'suppressMessages(bspm::enable())' "$RPROFILE" || echo 'suppressMessages(bspm::enable())' | sudo tee -a "$RPROFILE" > /dev/null
grep -qxF 'options(bspm.version.check=FALSE)' "$RPROFILE" || echo 'options(bspm.version.check=FALSE)' | sudo tee -a "$RPROFILE" > /dev/null
The bspm helper intercepts install.packages() and installs the matching Ubuntu package from r2u instead of compiling from CRAN source. The grep checks prevent duplicate Rprofile.site entries if you rerun the setup block.
Clean Up the Legacy c2d4u Launchpad PPA
The c2d4u Launchpad page now displays “CURRENTLY NOT UPDATED”, and CRAN’s Ubuntu README directs users to r2u for maintained binaries. Remove the dormant PPA to avoid stale packages and signature warnings.
To clean up the legacy PPA, detach it, delete any leftover files, and refresh APT:
if command -v add-apt-repository >/dev/null 2>&1; then
sudo add-apt-repository --remove ppa:c2d4u.team/c2d4u4.0+
fi
sudo rm -f /etc/apt/sources.list.d/c2d4u-team-ubuntu-c2d4u4_0_*.list /etc/apt/sources.list.d/c2d4u-team-ubuntu-c2d4u4_0_*.sources
sudo apt update
For a broader cleanup workflow, use the Ubuntu PPA removal guide to review leftover source files, keys, and packages.
Build R from Source (Advanced Users)
Building from source requires manual updates whenever new R versions are released. You must download, compile, and reinstall each version yourself; there are no automatic security updates through APT. Only choose this path if you genuinely need custom compiler flags or experimental features. For production systems or shared servers, use the CRAN repository or r2u binaries instead.
For advanced users who need the latest source release or custom compiler flags, a source build gives you direct control over the prefix, linked libraries, and rebuild timing. Use it only when the APT methods do not match your requirements.
Install Build Dependencies
Before compiling R, install compiler tools and development libraries. These dependencies include GCC, Fortran compilers, and essential development headers:
sudo apt install build-essential gcc gfortran curl wget libreadline-dev libx11-dev libxt-dev libpcre2-dev zlib1g-dev libbz2-dev liblzma-dev libcurl4-openssl-dev libssl-dev libjpeg-dev libpng-dev libtiff-dev libicu-dev libxml2-dev libblas-dev liblapack-dev
Download and Extract R Source Code
Use one terminal session for the next block because the detected version is reused for the download and extraction steps:
If you prefer manual downloads, grab the latest tarball from CRAN’s R-4.x source directory and replace the file name in the commands below.
cd /tmp
LATEST_TARBALL=$(curl -fsSL https://cran.r-project.org/src/base/R-4/ | grep -oP 'R-4\.\d+\.\d+\.tar\.gz' | sort -V | tail -1)
if [ -z "$LATEST_TARBALL" ]; then
echo "Could not detect the latest R 4.x tarball."
exit 1
fi
R_VERSION="${LATEST_TARBALL%.tar.gz}"
echo "Downloading ${R_VERSION}..."
wget -q "https://cran.r-project.org/src/base/R-4/${LATEST_TARBALL}"
tar xzf "${LATEST_TARBALL}"
cd "${R_VERSION}"
This command sequence parses CRAN’s source directory to find the newest R 4.x release, stops if no tarball is detected, downloads the archive, and extracts it. As of April 2026, the latest source tarball was R 4.6.0; your version may be newer when you run it.
Configure and Compile R
Inside the extracted directory, configure the build with optimization flags and then compile using multiple processor cores. This process may take 5-15 minutes depending on your hardware:
./configure --prefix=/usr/local --enable-R-shlib && make -j$(nproc)
Install and Verify Source-Built R
Once compilation completes successfully, install R system-wide and verify the installation:
sudo make install && R --version
Update a Source-Built R Installation
Source-compiled R requires manual updates when new versions are released. The following script adds safety checks, pulls the latest CRAN tarball, and rebuilds R; it assumes the build dependencies from earlier are installed. Create the script in your home directory first, then install it into your PATH:
nano ~/update-r-source
Paste the following script content:
#!/usr/bin/env bash
# R source update script
# Downloads and compiles the latest stable R release from CRAN
set -euo pipefail
REPO_URL="https://cran.r-project.org/src/base/R-4/"
BUILD_DIR="$HOME/r-build"
LOG_FILE="$BUILD_DIR/update.log"
for cmd in curl wget tar make gcc gfortran; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: $cmd is required. Install the build dependencies first."
exit 1
fi
done
if ! command -v R >/dev/null 2>&1; then
echo "Error: R is not installed. Build and install R first."
exit 1
fi
echo "Fetching latest R version from CRAN..."
LATEST_TARBALL=$(curl -fsSL "$REPO_URL" | grep -oP 'R-4\.\d+\.\d+\.tar\.gz' | sort -V | tail -1)
if [ -z "$LATEST_TARBALL" ]; then
echo "Error: Could not determine the latest R version from CRAN."
exit 1
fi
LATEST="${LATEST_TARBALL%.tar.gz}"
VERSION="${LATEST#R-}"
CURRENT=$(R --version 2>/dev/null | head -1 | grep -oP '\d+\.\d+\.\d+' || echo "not installed")
echo ""
echo "Current installed version: R ${CURRENT}"
echo "Latest available version: R ${VERSION}"
echo ""
if [ "${CURRENT}" = "${VERSION}" ]; then
echo "Already up to date."
exit 0
fi
read -r -p "Continue with update? (y/n) " -n 1
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Update cancelled."
exit 0
fi
mkdir -p "$BUILD_DIR"
echo "$(date): Updating to R ${VERSION}" >> "$LOG_FILE"
echo "Downloading R ${VERSION}..."
cd "$BUILD_DIR"
rm -rf R-*/
wget -q "${REPO_URL}${LATEST_TARBALL}"
echo "Extracting source code..."
tar xzf "${LATEST_TARBALL}"
cd "${LATEST}"
echo "Configuring build options..."
./configure --prefix=/usr/local --enable-R-shlib
echo "Compiling R (this may take 5-15 minutes)..."
make -j"$(nproc)"
echo "Installing R (requires sudo password)..."
sudo make install
echo ""
echo "Update complete!"
R --version | head -1
echo "$(date): Updated to $(R --version | head -1)" >> "$LOG_FILE"
The script builds in ~/r-build and logs updates to ~/r-build/update.log, making it easy to review past runs.
Avoid automating this with cron. Compilation can fail due to missing dependencies, failed tests, or network issues, so run the script manually and monitor the output.
Save the file by pressing Ctrl+O, then Enter, and exit with Ctrl+X. Install the helper command and run it:
sudo install -m 755 ~/update-r-source /usr/local/bin/update-r-source
update-r-source
When you are already current, the script exits quickly:
Fetching latest R version from CRAN... Current installed version: R 4.6.0 Latest available version: R 4.6.0 Already up to date.
When an update is available, you will see output similar to:
Fetching latest R version from CRAN... Current installed version: R 4.5.3 Latest available version: R 4.6.0 Continue with update? (y/n) y Downloading R 4.6.0... Extracting source code... Configuring build options... Compiling R (this may take 5-15 minutes)... Installing R (requires sudo password)... [sudo] password for user: Update complete! R version 4.6.0 (2026-04-24) -- "Because it was There"
The script compares your current version against the latest CRAN release, asks for confirmation before proceeding, and displays progress messages throughout the compilation process. Run this script periodically to stay current with R releases.
Troubleshooting Common R Installation Issues
GPG Signature Verification Failed
If apt update reports signatures could not be verified, first confirm the GPG key downloaded correctly to /usr/share/keyrings/cran.gpg and matches the expected fingerprint (E298 A3A8 25C0 D65D FD57 CBB6 5171 6619 E084 DAB9). Re-download the key if the file is corrupt or missing:
curl -fsSL https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo gpg --dearmor --yes -o /usr/share/keyrings/cran.gpg
gpg --show-keys --with-fingerprint /usr/share/keyrings/cran.gpg
Package Compilation Fails During install.packages()
When compiling from source, R packages often require system development libraries. Install r-base-dev for compiler tools, then add specific libraries as error messages indicate: libssl-dev for SSL support, libcurl4-openssl-dev for network packages, and libxml2-dev for XML parsing. The r2u repository avoids most of this work by providing prebuilt binaries.
sudo apt install r-base-dev libssl-dev libcurl4-openssl-dev libxml2-dev
Permission Denied When Installing Packages
If install.packages() fails with permission errors, you are likely running R as root (sudo R) but trying to install to a user library, or running as a regular user trying to write to /usr/lib/R/library/. To resolve this, run R without sudo for personal package installation, or use sudo -i R only when installing system-wide packages intentionally.
Repository Configuration Conflicts
Mixing the official CRAN repository with the now-deprecated c2d4u PPA causes version conflicts and signature warnings. To resolve this, remove the c2d4u PPA completely (see the “Clean Up the Legacy c2d4u Launchpad PPA” section above) and rely on the official CRAN repository or r2u for binary packages.
R Version Mismatch After Update
If R --version shows an older version than expected after installation, first check that /usr/bin/R points to the correct binary. Typically, when building from source with custom prefixes, your PATH may prioritize the system R over your compiled version. To diagnose this issue, verify which R binary is active:
which R
R --version
Remove R from Ubuntu
If you no longer need R on your system, remove the APT packages, clean up optional CRAN or r2u repository files, and delete user-installed packages only when you are sure you do not need them.
Remove R Packages
First, remove the core R packages and any example r2u packages you installed from this guide. The --purge flag removes package configuration files along with the packages, and the dry-run shows what APT would autoremove afterward:
sudo apt remove --purge r-base r-base-dev r-recommended r-cran-jsonlite r-cran-bspm
sudo apt autoremove --purge --dry-run
Review the dry-run output before running the final autoremove command. If APT lists packages you still need for other software, skip autoremove or remove only the R-specific packages you recognize. If the list is safe, run:
sudo apt autoremove --purge
Remove Optional Repository Files
Next, remove the CRAN and r2u repository configurations and GPG keys to prevent future updates:
sudo rm -f /etc/apt/sources.list.d/cran.sources /etc/apt/sources.list.d/cranapt.sources
sudo rm -f /usr/share/keyrings/cran.gpg /usr/share/keyrings/cranapt.gpg
sudo rm -f /etc/apt/preferences.d/99cranapt
sudo apt update
Remove Source-Built R Files (Optional)
Only run these commands if you built R from source with the
--prefix=/usr/localexample in this guide. If you used a custom prefix such as/usr/local/R/4.6.0, remove that specific directory instead.
sudo rm -rf /usr/local/lib/R /usr/local/bin/R /usr/local/bin/Rscript
sudo rm -f /usr/local/bin/update-r-source
rm -rf "$HOME/r-build"
Remove User-Installed R Packages (Optional)
The cleanup command permanently deletes R packages installed in your home directory, including custom configuration. If you have packages you want to keep or share, back them up first with
cp -r ~/R ~/R-backup.
R stores user-installed packages in your home directory. Remove this directory if you want a complete cleanup:
rm -rf "$HOME/R"
Verify R has been removed by confirming the command is no longer found:
which R
This command should return no output if R was successfully removed from your system.
Conclusion
R is ready on Ubuntu through the method that matches your release: Ubuntu’s archive for broad compatibility, CRAN APT packages where CRAN publishes your Ubuntu codename, or a source build for custom requirements. Use the R console for personal package libraries, r2u for fast system-wide CRAN binaries, or APT-managed r-cran-* packages for shared and reproducible systems.
Next Steps for R Development Environment
With R installed, you can now enhance your workflow with these complementary tools tailored for R development:
RStudio Desktop provides syntax highlighting, project management, and interactive debugging for R development. Download the latest version from the Posit website. It works with your R installation and supports R Markdown for reproducible research documents.
Version control becomes critical when collaborating on R projects or publishing reproducible research. Install Git on Ubuntu to track changes, manage branches, and integrate with GitHub or GitLab for sharing analysis scripts and package development.
Document rendering tools extend R’s capabilities for generating professional reports. For R Markdown documents and Shiny applications, install Pandoc (sudo apt install pandoc) and LaTeX (sudo apt install texlive-full) for PDF rendering capabilities.
Official R Resources
These upstream resources are useful when you need project documentation beyond Ubuntu installation and package setup:
- R Project Official Website: Visit the official R Project website for R project information, release news, and documentation.
- R for Ubuntu: Access the dedicated page for installing R on Ubuntu, including binaries and installation instructions.
- R Project Help: Find various help resources for R, including mailing lists, documentation, and user guides.
- R Manuals: Access a collection of manuals covering different aspects of R, from primary usage to advanced programming.
- R FAQs: Check upstream answers for language behavior, package installation, and common R environment questions.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="https://example.com">link</a><blockquote>quote</blockquote>