Debian already includes R, but the stable package can lag behind CRAN once a release settles. The cleanest way to install R on Debian with current CRAN builds is to add the CRAN Debian repository, then let APT manage R updates like any other system package.
CRAN maps Debian 13 (trixie) and Debian 12 (bookworm) to its R 4.6 suite, while Debian 11 (bullseye) remains on the R 4.5.1-compatible suite because the Bullseye backports base used for later builds is no longer available. Installing r-base-dev alongside R also prepares Debian for source-built CRAN packages, which is where many R setup problems appear after the runtime itself is working.
Install R on Debian
Use the CRAN repository when you want newer R releases than Debian’s default APT sources provide. Debian’s own package remains a good fallback for conservative systems that prioritize the distro-maintained version over the newest upstream release.
Update Debian Packages
Refresh APT metadata and apply available package updates before adding the CRAN source:
sudo apt update && sudo apt upgrade -y
These commands use
sudofor system-level package changes. If your account cannot run sudo yet, add the account to sudoers first or run the commands from a root shell. The Debian sudoers workflow is covered in Add a User to Sudoers on Debian.
Install CRAN Repository Prerequisites
Install the tools needed to download the signing key, validate HTTPS connections, and convert the key into an APT-readable keyring:
sudo apt install ca-certificates curl gpg -y
The curl command downloads the key over HTTPS, while gpg converts it into a binary keyring. For more download options, see the curl command guide.
Add the CRAN Signing Key
CRAN signs its Debian repository with the key fingerprint 95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7. Import that key into a dedicated APT keyring:
curl -fsSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7' | sudo gpg --dearmor --yes -o /usr/share/keyrings/cran.gpg
The --yes flag lets the command overwrite an older CRAN keyring during repairs or future key refreshes without opening an interactive prompt.
Add the CRAN Repository Source
Create a DEB822 source file that matches your Debian codename and architecture. CRAN publishes R 4.6 packages for Debian 13 and 12 on amd64 and arm64, while the older Debian 11 suite supports amd64, arm64, and i386. Sourcing /etc/os-release avoids a dependency on lsb_release, which is not guaranteed on minimal Debian installs:
. /etc/os-release
arch="$(dpkg --print-architecture)"
case "${VERSION_CODENAME}:${arch}" in
trixie:amd64|trixie:arm64) cran_suite="trixie-cran46/" ;;
bookworm:amd64|bookworm:arm64) cran_suite="bookworm-cran46/" ;;
bullseye:amd64|bullseye:arm64|bullseye:i386) cran_suite="bullseye-cran40/" ;;
*)
printf 'This CRAN Debian repository method supports Debian 13 and 12 on amd64 or arm64, and Debian 11 on amd64, arm64, or i386.\n' >&2
cran_suite=""
;;
esac
if [ -n "$cran_suite" ]; then
printf '%s\n' \
"Types: deb" \
"URIs: https://cloud.r-project.org/bin/linux/debian/" \
"Suites: ${cran_suite}" \
"Components:" \
"Architectures: ${arch}" \
"Signed-By: /usr/share/keyrings/cran.gpg" | sudo tee /etc/apt/sources.list.d/cran.sources > /dev/null
else
false
fi
The case block prevents Debian 13 and 12 from using the older R 4.5 suite, keeps Debian 11 on the last Bullseye-compatible CRAN suite, and stops before writing a source file on unsupported architectures. The Architectures: field also keeps multiarch systems from requesting CRAN indexes for foreign architectures this source does not support. The sudo tee part writes the root-owned source file. Plain shell redirection would run as your unprivileged user and fail on /etc/apt/sources.list.d/.
Refresh APT and Confirm the R Source
Refresh APT so Debian reads the new CRAN source:
sudo apt update
Relevant output includes a CRAN package fetch for your release:
Get:4 https://cloud.r-project.org/bin/linux/debian trixie-cran46/ InRelease Get:5 https://cloud.r-project.org/bin/linux/debian trixie-cran46/ Packages Reading package lists...
Confirm that r-base now prefers the CRAN package:
apt-cache policy r-base
On Debian 13, the relevant lines should resemble:
r-base:
Installed: (none)
Candidate: 4.6.0-2~trixiecran.0
Version table:
4.6.0-2~trixiecran.0 500
500 https://cloud.r-project.org/bin/linux/debian trixie-cran46/ Packages
4.5.0-3 500
500 http://deb.debian.org/debian trixie/main amd64 Packages
Debian 12 should show a bookwormcran CRAN candidate from bookworm-cran46/. Debian 11 should show a bullseyecran candidate from bullseye-cran40/, but CRAN caps Bullseye at R 4.5.1 because the Bullseye backports base used for later builds has been discontinued.
Install R Base and Development Files
Install the R runtime and the development package used by many CRAN packages that compile C, C++, or Fortran code:
sudo apt install r-base r-base-dev -y
The r-base package installs R and the recommended statistical packages. The r-base-dev package adds compiler-facing headers and build helpers, which prevents common source-package failures when installing packages from CRAN.
Verify the installed R version:
R --version
Debian 13 and Debian 12 currently show R 4.6.0 from CRAN:
R version 4.6.0 (2026-04-24) -- "Because it was There" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu
Debian 11 currently shows R 4.5.1 from CRAN, with the codename Great Square Root.
Compare Debian and CRAN R Versions
The version gap is the main reason to use the CRAN repository instead of Debian’s default package. Current package candidates are:
| Debian Release | Default Debian Candidate | CRAN Candidate | Best Fit |
|---|---|---|---|
| Debian 13 (trixie) | 4.5.0-3 | 4.6.0-2~trixiecran.0 | Use CRAN for the current upstream branch. |
| Debian 12 (bookworm) | 4.2.2.20221110-2 | 4.6.0-2~bookwormcran.0 | Use CRAN for current R and newer package compatibility. |
| Debian 11 (bullseye) | 4.0.4-1 | 4.5.1-1~bullseyecran.0 | Use CRAN only when you still need the newer Bullseye-compatible 4.5 branch. |
If your system needs only the Debian-maintained version, install r-base from the default repositories and skip the CRAN source. If you need current CRAN package compatibility on Trixie or Bookworm, the CRAN repository is the better fit. Bullseye remains useful for older systems, but it does not receive the R 4.6 suite.
CRAN split R 4.6 packages into new
trixie-cran46/andbookworm-cran46/suites. If your system previously usedtrixie-cran40/orbookworm-cran40/, update locally compiled R packages before switching suites, then runupdate.packages(checkBuilt = TRUE)again after the R upgrade so packages with compiled code rebuild against the new runtime.
Install R Packages from CRAN
CRAN packages install best as your normal user unless you deliberately manage a shared system library. Create your user library first so non-interactive installs do not try to write to /usr/local/lib/R/site-library. The path.expand() call matters because Debian’s default R user-library path uses ~:
mkdir -p "$(Rscript -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))')"
Install a package from CRAN with Rscript. This example uses jsonlite because it is small and confirms source-package compilation works:
Rscript -e 'install.packages("jsonlite", lib=path.expand(Sys.getenv("R_LIBS_USER")), repos="https://cloud.r-project.org")'
The install should end with a success line like this:
* DONE (jsonlite)
Confirm R can load the package:
Rscript -e 'library(jsonlite); cat("jsonlite loaded\n")'
jsonlite loaded
Install System Libraries for Popular R Packages
Packages such as curl, openssl, xml2, ragg, systemfonts, and many tidyverse dependencies need Debian development libraries before they can compile cleanly. Install the common set with:
sudo apt install libssl-dev libxml2-dev libcurl4-openssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev -y
After those libraries are present, install larger R packages the same way. For example, Rscript -e 'install.packages("tidyverse", lib=path.expand(Sys.getenv("R_LIBS_USER")), repos="https://cloud.r-project.org")' installs tidyverse into your user library.
Update or Remove User-Installed R Packages
Update packages installed in your R libraries with:
Rscript -e 'update.packages(ask = FALSE, checkBuilt = TRUE, repos="https://cloud.r-project.org")'
The checkBuilt = TRUE option rebuilds packages that were compiled under an older R release, which matters after major R upgrades.
Remove a user-installed package by name:
Rscript -e 'remove.packages("jsonlite", lib=path.expand(Sys.getenv("R_LIBS_USER")))'
Update R on Debian
After the CRAN source is configured, normal APT updates include new R packages when CRAN publishes them. To check only the R packages documented here, refresh APT and request package upgrades without installing R on systems where it is absent:
sudo apt update
sudo apt install --only-upgrade r-base r-base-core r-base-dev r-recommended
If a package is already current, APT reports it as the newest version. If --only-upgrade skips a package, that package is not installed on the system.
Install RStudio and R Markdown Tools on Debian
RStudio is separate from R itself. Posit’s current platform support matrix lists RStudio Desktop for Debian 13 and Debian 12 on x86-64; Debian 11 is not listed for current Desktop builds. Use the official RStudio Desktop download page and confirm the Debian package still matches your release before installing it.
After downloading the Debian-compatible .deb file from Posit, install it from the download directory with APT. Avoid copying older version-specific filenames from search results because Posit changes the package name as RStudio Desktop releases move:
sudo apt install ./rstudio-*.deb
Launch RStudio Desktop from the applications menu or with rstudio if the package adds the launcher to your shell path. Posit’s desktop package does not add a normal Debian APT repository, so update it by downloading a newer .deb from Posit and installing it over the existing package. Remove the desktop package with:
sudo apt remove rstudio
RStudio Server is a different Posit product. Installing R or RStudio Desktop does not create a local RStudio Server service, so use Posit’s Server documentation if your search intent is browser-based multi-user access.
Install R Markdown System Tools
For R Markdown reports, Debian packages provide Pandoc and the LaTeX components needed for common HTML and PDF output:
sudo apt install pandoc texlive-latex-base texlive-latex-extra texlive-fonts-recommended -y
Install the R-side rmarkdown package afterward from CRAN, using the same user-library pattern shown earlier:
Rscript -e 'install.packages("rmarkdown", lib=path.expand(Sys.getenv("R_LIBS_USER")), repos="https://cloud.r-project.org")'
For version control or editing outside RStudio, Install Git on Debian and Install Visual Studio Code on Debian are practical next tools for R project work.
Troubleshoot R on Debian
Fix CRAN NO_PUBKEY Errors
If sudo apt update reports a missing CRAN signing key, APT cannot verify the repository metadata. The error looks like this:
W: GPG error: https://cloud.r-project.org/bin/linux/debian bookworm-cran46/ InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY DC78B2DDEABC47B7
Remove the stale keyring, re-import the CRAN key, and refresh APT again:
sudo rm -f /usr/share/keyrings/cran.gpg
curl -fsSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x95C0FAF38DB3CCAD0C080A7BDC78B2DDEABC47B7' | sudo gpg --dearmor --yes -o /usr/share/keyrings/cran.gpg
sudo apt update
Fix an Incorrect CRAN Debian Codename
If APT says the CRAN repository has no release file, inspect the source file:
cat /etc/apt/sources.list.d/cran.sources
The Suites: line must match your release, such as trixie-cran46/, bookworm-cran46/, or bullseye-cran40/. If a Debian 13 or Debian 12 system still shows a cran40 suite, remove the stale source file and recreate it with the current CRAN repository source command. Confirm your Debian codename with:
. /etc/os-release
printf '%s\n' "$VERSION_CODENAME"
Fix R Package Library Permission Errors
If R tries to install packages into a system directory, you may see this prompt:
Warning in install.packages("jsonlite") :
'lib = "/usr/local/lib/R/site-library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel)
Use a personal library for single-user work. Create it explicitly, then retry the package install:
mkdir -p "$(Rscript -e 'cat(path.expand(Sys.getenv("R_LIBS_USER")))')"
Reserve system-wide R package installs for shared machines where you intentionally manage one library for multiple users.
Fix R Package Compilation Failures
Compilation errors usually mean a Debian development library is missing. Install the common libraries first:
sudo apt install libssl-dev libxml2-dev libcurl4-openssl-dev libfontconfig1-dev libharfbuzz-dev libfribidi-dev -y
If the error names another library, search Debian’s package index for the matching -dev package and install that package before retrying the R install.
Remove R from Debian
Remove the metapackage, the core package that provides the R binary, the development package, and the recommended package set:
sudo apt remove --purge r-base r-base-core r-base-dev r-recommended
APT will also remove the recommended r-cran-* packages that depend on r-base-core. Review the package list before confirming the removal.
Afterward, verify the main package is no longer installed:
dpkg -l r-base r-base-core r-base-dev r-recommended | grep '^ii'
The grep filter shows only packages still marked as installed. If the command returns no output, those packages are no longer installed.
Remove the CRAN source and keyring only if you do not plan to reinstall R from CRAN:
sudo rm -f /etc/apt/sources.list.d/cran.sources
sudo rm -f /usr/share/keyrings/cran.gpg
sudo apt update
Confirm the CRAN candidate is gone. Debian’s default package may still appear as the candidate, which is normal because it comes from Debian’s own repositories:
apt-cache policy r-base
r-base:
Installed: (none)
Candidate: 4.5.0-3
Version table:
4.5.0-3 500
500 http://deb.debian.org/debian trixie/main amd64 Packages
APT may also report old kernels or other unrelated packages as autoremovable on reused systems. Run sudo apt autoremove only after reviewing the list and confirming it contains packages you actually want to remove.
Remove User R Packages and History
The following command permanently deletes user-level R data, including packages under
~/R/, command history in~/.Rhistory, and settings under~/.R/. Back up any packages, scripts, or history you want to keep before running it.
rm -rf ~/.R ~/.Rhistory ~/R
Conclusion
R is available on Debian through CRAN’s APT repository, with r-base-dev ready for source-built packages and user-level libraries available for project work. For broader analysis stacks, pair R with Install SQLite on Debian for local datasets or Install MariaDB on Debian for server-backed workflows.


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><blockquote>quote</blockquote>