Install R in Ubuntu with APT, Ubuntu’s package manager, from Ubuntu’s archive or CRAN’s signed repository. R is a programming language and environment for statistical computing and graphics.
Choose Ubuntu’s archive for its release-maintained package, or CRAN when its signed suite offers the R version your project needs. Check your Ubuntu codename and APT’s candidate before installing, then run a saved script or add R packages.
Why Ubuntu and CRAN install different R releases
APT picks a package version from its configured sources. Ubuntu’s archive and CRAN are separate repositories, so the candidate depends on which source you enable for your Ubuntu codename.
| Package source | r-base-core version or candidate check | Choose it when |
|---|---|---|
| Ubuntu 26.04 Resolute archive (amd64) | 4.5.2-1ubuntu2 | You want the release-maintained R build. |
| Ubuntu 24.04 Noble archive (arm64) | 4.3.3-2build2 | You want Noble’s release-maintained candidate. |
| CRAN for Resolute (amd64 and arm64) | Run apt update, then check apt policy r-base. | You need the candidate from the matching CRAN suite. |
| CRAN for Noble (amd64 and arm64) | Run apt update, then check apt policy r-base. | You need the candidate from the matching CRAN suite. |
| CRAN for Jammy (amd64 and arm64) | Run apt update, then check apt policy r-base. | You need the candidate from the matching CRAN suite. |
CRAN’s supported-release list separates its current R release from cran40, which marks binary compatibility, not R 4.0. After adding the source for your codename, run apt policy r-base to see the candidate selected from your configured sources.
Check the Ubuntu codename and architecture
CRAN’s current list supports Ubuntu 26.04 Resolute, 24.04 Noble, and 22.04 Jammy with amd64 and arm64 builds for each suite.
. /etc/os-release
printf '%s\n' "$VERSION_CODENAME"
dpkg --print-architecture
I ran both checks on Noble arm64 and got noble and arm64, which selects the matching noble-cran40 suite. If you use an Ubuntu derivative, use our Ubuntu version check to find its base codename, then choose a suite CRAN lists.
Install R from the Ubuntu archive
Ubuntu installs the archive package from its configured repositories without a CRAN key or separate source file.
sudo apt update
apt policy r-base
sudo apt install --no-install-recommends r-base
R --version
I ran apt policy r-base on Noble arm64 and got candidate 4.3.3-2build2 from noble/universe. Check the Candidate field and release line to confirm APT chose the source you intended.
Use APT package search to find package names, then list installed APT packages if you need to check which R packages are already present.

The screenshot records package metadata from a Noble arm64 index before installation. Your result can differ with another Ubuntu release, architecture, or configured APT source.
Install current R from CRAN
CRAN signs its Ubuntu package index with a public key. I verified the downloaded key against CRAN’s published fingerprint, E298 A3A8 25C0 D65D FD57 CBB6 5171 6619 E084 DAB9.
The keyring file and the source entry below keep that key scoped to CRAN through APT’s Signed-By option. Ubuntu’s sources.list manual documents the source-file syntax, and apt-secure explains repository signature checks.
set -euo pipefail
sudo apt update
sudo apt install --no-install-recommends ca-certificates curl gnupg
. /etc/os-release
: "${VERSION_CODENAME:?Check CRAN's supported Ubuntu release list first}"
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee /etc/apt/keyrings/cran-r-project.asc >/dev/null
sudo chmod 0644 /etc/apt/keyrings/cran-r-project.asc
gpg --show-keys --with-fingerprint /etc/apt/keyrings/cran-r-project.asc
printf 'deb [signed-by=/etc/apt/keyrings/cran-r-project.asc] https://cloud.r-project.org/bin/linux/ubuntu %s-cran40/\n' "$VERSION_CODENAME" | sudo tee /etc/apt/sources.list.d/cran-r-project.list
sudo apt update
apt policy r-base
sudo apt install --no-install-recommends r-base
Compare the GPG fingerprint with CRAN’s published value, then run apt update and check apt policy r-base.
If apt policy r-base still names Ubuntu or apt update reports a missing Release file, fix the suite or key before installing from CRAN.
CRAN uses a suite-specific package source, but a CRAN release number alone does not tell you which package APT will install. After adding the matching suite, run apt policy r-base and check the Candidate field and repository origin.
Run an R script with Rscript
R opens an interactive console. The Rscript manual documents the file argument and version option, so use Rscript when you want a saved script to run and return to the shell.
Save this sample as mean.R to average three values and print the result.
values <- c(2, 4, 6)
print(mean(values))
Rscript mean.R
In my isolated test environment, Rscript 4.6.1 ran mean.R and printed [1] 4. The [1] marks the first printed value, and 4 is the calculated mean.
![Rscript runs mean.R and prints [1] 4 in the terminal.](https://www.linuxfordevices.com/wp-content/uploads/2026/09/mean-output.png)
If Rscript cannot open mean.R, run it from the directory where you saved the file.
Add CRAN packages and RStudio Desktop
R scripts run from the shell without a desktop IDE, and R packages install separately.
Install an R package
For packages compiled from source, CRAN’s full instructions recommend r-base-dev for the baseline build tools. Some packages also need system development libraries named in their installation notes.
sudo apt install r-base-dev
Rscript -e 'install.packages("jsonlite", repos = "https://cloud.r-project.org")'
Keep sudo on the apt command, but leave it off install.packages to install into your user library. Add a named Ubuntu development package when a source-build error requires it.
Add the optional RStudio IDE
RStudio Desktop is an IDE, not the R runtime. Install R first, then choose a package for your Ubuntu release and architecture from Posit’s current downloads.
sudo apt install ./rstudio-*.deb
Run this from a directory with one downloaded RStudio .deb file. Our guide to installing DEB files on Ubuntu covers the local-file syntax and APT resolves the package dependencies.
Fix “deb: command not found”
Bash tries to run the repository declaration because you entered it at the prompt. It looks for an executable named deb before APT reads the source.
| What you see | Cause | Next check |
|---|---|---|
| deb: command not found | The shell parsed the source line as a command. | Write it to cran-r-project.list instead of running it. |
| NO_PUBKEY during apt update | The source cannot find a trusted key at its Signed-By path. | Check the GPG fingerprint and keyring path. |
| An HTTP 404 or missing Release file | The selected CRAN suite does not match a supported Ubuntu codename. | Compare lsb_release -cs with CRAN’s release list. |
| Ubuntu remains the candidate | APT did not load the CRAN package index. | Read apt update errors, then inspect apt policy r-base. |
. /etc/os-release
printf 'deb [signed-by=/etc/apt/keyrings/cran-r-project.asc] https://cloud.r-project.org/bin/linux/ubuntu %s-cran40/\n' "$VERSION_CODENAME" | sudo tee /etc/apt/sources.list.d/cran-r-project.list
sudo apt update
apt policy r-base</pre>
After you remove /etc/apt/sources.list.d/cran-r-project.list, APT stops checking CRAN. R and packages in your user library remain installed, so follow the Ubuntu package-removal guide to remove R itself.
Check the R version your scripts will call
Run Rscript –version in the same shell as your project, so the result identifies the executable that will run its scripts.
Rscript --version
Rscript (R) version 4.6.1 (2026-06-24)
My isolated test environment reported R 4.6.1. The version line identifies the interpreter Rscript found there. Use the same shell to check your project environment.
If your project pins R 4.6.1, run apt policy r-base after apt update and confirm the Candidate field shows a 4.6.1 build from the intended CRAN suite before installing packages for that environment.
Frequently asked questions
How do I install R on Ubuntu?
Run sudo apt update and sudo apt install r-base to install Ubuntu’s archive version. Use CRAN’s signed APT repository if your project needs the current R package series.
How do I install the current R release on Ubuntu?
Check the Ubuntu codename and architecture against CRAN’s supported list, add CRAN’s signed source, run apt update, and confirm the candidate with apt policy r-base before installing.
Why does the shell say deb: command not found?
The shell tried to run the first word of an APT source declaration as a program. Save the line in a file under /etc/apt/sources.list.d/ instead, then run sudo apt update.
Do I need RStudio to install R?
No. RStudio Desktop is an optional IDE, and the R runtime is installed separately from Ubuntu or CRAN.
When should I install r-base-dev?
Install r-base-dev when an R package needs to compile from source. Some packages also require separate Ubuntu development libraries.
