Install R with APT on Ubuntu 26.04 LTS or 24.04 LTS, then add RStudio Desktop if you want a graphical editor. R handles the calculations and plots. RStudio gives you a place to write scripts, run code, and see the results.
- Use Ubuntu 26.04 LTS or 24.04 LTS, a Bash terminal, internet access, and sudo access for APT.
- R runs on
amd64andarm64. The RStudio Desktop installer requiresamd64and a graphical Ubuntu session. - Run R, RStudio, and R package installs as your regular user.
On this page
ToggleInstall R on Ubuntu
. /etc/os-release
printf '%s\n' "$PRETTY_NAME" "$VERSION_CODENAME"
dpkg --print-architecture
Expect resolute on 26.04 or noble on 24.04. The architecture tells you whether to use the RStudio installer or continue with R in the terminal.
sudo apt update && apt-cache policy r-base
If APT shows no candidate on a standard installation, enable Ubuntu’s Universe repository and check again.
sudo add-apt-repository -y universe
sudo apt update && apt-cache policy r-base
sudo apt install -y r-base r-base-dev && R --version && Rscript --version
r-base-dev brings in compilers and development files needed to build many R packages from source. The version checks confirm that the interactive interpreter and script runner are available.
Get a newer R release from CRAN
On both amd64 and arm64, Ubuntu’s Universe repository provides R 4.5.2 on Ubuntu 26.04 LTS and R 4.3.3 on Ubuntu 24.04 LTS. Either works for the examples below. Use CRAN’s official Ubuntu repository for the current R 4.6.x series if a course or package needs it.
CRAN uses resolute-cran40/ for Ubuntu 26.04 and noble-cran40/ for 24.04. The -cran40/ suffix identifies the R 4.0+ binary compatibility series. It currently serves R 4.6.x. CRAN lists c2d4u as on hiatus.
If CRAN already appears in your APT sources, update the existing entry in place and use the verified key below. Duplicate entries with different signing options can prevent APT from updating.
sudo apt install -y curl ca-certificates gnupg
The next block checks Michael Rutter’s primary key fingerprint before saving it at /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc. It assigns that key to the CRAN source. If the fingerprint check fails, stop and check the official CRAN instructions.
(
set -eu
set -o pipefail
. /etc/os-release
case "$ID:$VERSION_CODENAME:$(dpkg --print-architecture)" in
ubuntu:resolute:amd64|ubuntu:resolute:arm64|ubuntu:noble:amd64|ubuntu:noble:arm64) ;;
*) printf '%s\n' 'Use Ubuntu 26.04 or 24.04 on amd64 or arm64.' >&2; exit 1 ;;
esac
key=$(mktemp)
trap 'rm -f -- "$key"' EXIT
curl -fsSL https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc -o "$key"
fingerprint=$(gpg --batch --show-keys --with-colons "$key" |
awk -F: '$1 == "fpr" && !seen++ { print $10 }')
if [ "$fingerprint" != E298A3A825C0D65DFD57CBB651716619E084DAB9 ]; then
printf '%s\n' 'CRAN key fingerprint does not match. Stopping.' >&2
exit 1
fi
sudo install -m 0644 "$key" /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
printf 'deb [signed-by=/etc/apt/trusted.gpg.d/cran_ubuntu_key.asc] https://cloud.r-project.org/bin/linux/ubuntu %s-cran40/\n' "$VERSION_CODENAME" |
sudo tee /etc/apt/sources.list.d/cran-r.list >/dev/null
sudo apt update
apt-cache policy r-base
)
Check that apt-cache policy shows the matching CRAN source and a 4.6.x candidate. Then install or upgrade both packages and check the active version.
sudo apt install -y r-base r-base-dev && R --version
Install RStudio Desktop on Ubuntu
Install R first. On amd64, download the Linux .deb from Posit’s RStudio Desktop downloads. The same installer targets Ubuntu 22, 24, and 26. For RStudio Desktop 2026.11.0, the filename is rstudio-2026.11.0-203-amd64.deb.
In the download folder, make sure only the desired installer matches rstudio-*.deb. APT installs the local file and resolves its dependencies.
cd ~/Downloads && sudo apt install -y ./rstudio-*.deb
If the install succeeds but prints an _apt sandbox warning, APT’s unprivileged user could not read the local file. You can ignore that warning after a successful install. To avoid it, put the readable installer in an accessible directory under /tmp and run the same APT command from there.
Open RStudio from the applications menu and enter the line below in the Console. Compare the result with R --version in the terminal.
R.version.string
Run your first R script and install a package
In RStudio, choose File → New Project → New Directory → New Project. Name it r-first-project and create it in your home folder. Open a new R script, paste the code below, and save it as mtcars-summary.R in the project. For a terminal-only setup, create the same folder and file with a text editor.
print(summary(mtcars[c("mpg", "wt")]))
if (!interactive()) {
png("mtcars-mpg.png", width = 960, height = 640, type = "cairo")
}
plot(mpg ~ wt, data = mtcars, pch = 19, col = "steelblue",
xlab = "Weight (1,000 lb)", ylab = "Miles per gallon",
main = "Fuel economy and car weight")
if (!interactive()) {
invisible(dev.off())
message("Saved mtcars-mpg.png")
}
Click Source in RStudio. The Console shows the summary and the Plots pane shows fuel economy against car weight. Each dot represents one car. The dataset has 32 cars, and median fuel economy is 19.2 miles per gallon.
Run the same file from Bash. The script opens a PNG device in non-interactive sessions, so it works without a desktop. Each rerun replaces mtcars-mpg.png in the project folder.
cd ~/r-first-project && Rscript mtcars-summary.R
In the RStudio Console or at the interactive R prompt, install a small package for reading and writing JSON. If R asks to use a personal library and offers to create it, answer yes to both. R usually creates a version-specific directory under ~/R/ because your account cannot write to the system library.
install.packages("jsonlite", repos = "https://cloud.r-project.org")
packageVersion("jsonlite")
The second line prints the installed package version. To use the terminal for this part, type R in Bash before entering the R commands.
Troubleshoot, update, or remove R and RStudio
Use the issue that matches your error. Review APT’s proposed changes before purging packages.
Run dpkg --print-architecture. Posit’s amd64 installer needs an amd64 Ubuntu installation. On arm64, use R and Rscript with your preferred editor.
Read the first configuration or compiler error. If it names curl, OpenSSL, or XML headers, install the matching Ubuntu development package. This command installs all three. Retry the package install as your regular user.
sudo apt install -y libcurl4-openssl-dev libssl-dev libxml2-dev
Update R from the APT source you chose. For R packages, run update.packages(repos = "https://cloud.r-project.org", ask = TRUE) as your regular user. A new R minor series may use a new personal library. Update RStudio by downloading a newer .deb and repeating Step 5 with that installer.
sudo apt update && sudo apt install --only-upgrade r-base r-base-dev
Close R and RStudio first. Run the RStudio command only if you want to remove the IDE. To remove the APT-installed R runtime, include r-base-core. Purging only the r-base metapackage leaves the runtime installed. APT can also remove packages that depend on R, so review the list before confirming.
sudo apt purge rstudio
sudo apt purge r-base r-base-core r-base-dev r-recommended
If you added CRAN in Step 4 and no longer need it, remove the source and refresh APT. The key can be removed if no other source uses it.
sudo rm -i /etc/apt/sources.list.d/cran-r.list
sudo apt update
These commands leave your project folders, .Rproj files, .R scripts, the ~/R personal library, and ~/.config/rstudio settings on disk. They stay there unless you remove them yourself.
Frequently asked questions
Can I use R without RStudio?
Yes. Start R in the terminal for an interactive session, or use Rscript to run a saved .R file. RStudio Desktop is an optional editor and interface.
Does the RStudio Desktop installer work on ARM64 Ubuntu?
Posit’s official Linux desktop installer targets amd64. On ARM64 Ubuntu, you can install and run R and Rscript using the same R steps in this guide.
Why did R ask to create a personal library?
Your regular account cannot write to the system R library. Let R create a version-specific library under ~/R so you can install packages without sudo.
Helpful Resources
Related Ubuntu guides
- Query CSV and Parquet files with DuckDB on Ubuntu
- Set up Julia for numerical computing on Ubuntu
- Manage Python projects with uv on Ubuntu
