R is a language and environment for statistical computing and graphics. Rscript is the non-interactive front-end that runs .R files from the shell—what you want for cron jobs, CI pipelines, or calling R from PHP with exec (Stack Overflow).
On Ubuntu, Rscript is not a separate download. It installs with r-base (which depends on r-base-core) from universe. Ask Ubuntu walks through the same starting point—sudo apt install r-base; this guide adds verification, a CRAN repository path for newer R on LTS releases, a runnable script example, and uninstall steps.
Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; R 4.4.3;
Rscriptat/usr/bin/Rscript.
Rscript (from r-base-core) with the littler package, which provides a different scripting helper. For batch .R files, install r-base and use Rscript.
Prerequisites
- Ubuntu 22.04 LTS, 24.04 LTS, or newer (25.04 tested here) on amd64 (CRAN also publishes arm64 for supported LTS suites).
- sudo for apt installs.
- universe enabled (
r-baseis packaged there).
See check Ubuntu version if you are unsure which release you are on.
Quick command summary
| Task | Command |
|---|---|
| Install | sudo apt update && sudo apt install -y r-base |
| Verify | R --version and Rscript --version |
| Run a script | Rscript example.R |
| One-liner | Rscript -e 'print(1+1)' |
| Update | sudo apt update && sudo apt upgrade r-base |
| Uninstall | sudo apt purge -y r-base |
Choose an install method
| Method | Best for | Jump to |
|---|---|---|
Ubuntu universe (r-base) |
Most users, servers, and cron/CI jobs that accept Ubuntu’s pinned R | Method 1 |
| CRAN apt repository | LTS desktops or servers that need a newer R than universe ships | Method 2 |
For most Ubuntu systems, sudo apt install r-base is enough. Add CRAN only on a supported LTS codename when you need a newer R build.
Method 1: Install R and Rscript from Ubuntu universe (recommended)
Refresh indexes and check the candidate:
sudo apt update
apt-cache policy r-base r-base-coreOn Ubuntu 25.04:
r-base:
Candidate: 4.4.3-1
r-base-core:
Candidate: 4.4.3-1Install the metapackage (pulls in r-base-core, recommended CRAN R packages, and Rscript):
sudo apt install -y r-baseVerify the interactive shell and batch runner:
R --version
Rscript --version
which R RscriptR version 4.4.3 (2025-02-28) -- "Trophy Case"
Rscript (R) version 4.4.3 (2025-02-28)
/usr/bin/R
/usr/bin/RscriptUbuntu also ships hundreds of r-cran-* packages through apt—search before installing from source:
apt search '^r-cran-' | grep -i xtabler-cran-xtable/plucky 1:1.8-4-2 allMethod 2: Install R from the CRAN apt repository
CRAN’s Ubuntu README lists supported suites—typically jammy-cran40 (22.04) and noble-cran40 (24.04). If you run an interim release (for example 22.10 or 25.04), $(lsb_release -cs)-cran40 often fails with no Release file (Ask Ubuntu) because CRAN does not publish for every Ubuntu codename. On those releases, stay on Method 1 or point the suite at the nearest LTS you intentionally support.
Add the CRAN repository (deb822, Ubuntu 24.04 example)
Install tooling and import the signing key into /usr/share/keyrings/:
sudo apt install -y wget gpg
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | \
sudo gpg --dearmor -o /usr/share/keyrings/cran-archive-keyring.gpgCreate the DEB822 source file—use noble-cran40/ on 24.04 or jammy-cran40/ on 22.04:
sudo tee /etc/apt/sources.list.d/cran-r.sources > /dev/null <<'EOF'
Types: deb
URIs: https://cloud.r-project.org/bin/linux/ubuntu/
Suites: noble-cran40/
Components:
Signed-By: /usr/share/keyrings/cran-archive-keyring.gpg
EOFRefresh and install:
sudo apt update
sudo apt install -y r-base
R --version
Rscript --versionapt-key add and one-line deb format unless you are maintaining legacy docs—the keyring + .sources layout matches current Ubuntu apt security guidance and recent Ask Ubuntu answers.
Run an example R script with Rscript
An R script is a plain-text .R file with the same expressions you would type in the interactive R shell.
Create example.R:
nano example.R# Example R script
x <- 42
y <- 25
z <- x + y
w <- y / x
print("z")
print(z)
print("w")
print(w)Run it:
Rscript example.R[1] "z"
[1] 67
[1] "w"
[1] 0.5952381One-liner (no file):
Rscript -e 'print(1+1)'[1] 2From cron or PHP exec, use the full path so a minimal environment still finds R:
/usr/bin/Rscript /path/to/example.RInteractive R shell (optional)
Launch the REPL with uppercase R (not the littler package’s lowercase r):
Rprint("This article is about R")
quit(save = "no")Keep R and Rscript updated
sudo apt update && sudo apt upgrade -y r-base
Rscript --versionIf you use the CRAN repository, apt upgrade tracks CRAN builds once the source file is configured.
Uninstall R and Rscript
sudo apt purge -y r-base r-base-core
sudo apt autoremove -yIf you added CRAN:
sudo rm -f /etc/apt/sources.list.d/cran-r.sources
sudo apt updateConfirm removal:
Rscript --versionRscript: command not foundTroubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Rscript: command not found |
r-base not installed |
sudo apt install r-base or r-base-core |
Ubuntu suggests r-cran-littler for r |
Confusion with littler |
Use uppercase R for the REPL; use Rscript for scripts |
CRAN does not have a Release file |
Unsupported $(lsb_release -cs) (interim release) |
Use universe r-base, or set suite to jammy-cran40 / noble-cran40 on purpose |
apt cannot find r-base |
universe disabled | sudo add-apt-repository universe && sudo apt update |
| Script works in shell but not cron | PATH omits /usr/bin |
Call /usr/bin/Rscript explicitly in the crontab |
| Need IDE, not just CLI | RStudio is separate | Install RStudio or use R in the terminal—out of scope for Rscript alone |
References
- CRAN — R for Linux
- Stack Overflow — Rscript on Ubuntu
- Ask Ubuntu — Installing R on Ubuntu
- On-site: apt command, wget command, install cURL on Ubuntu, curl cheat sheet, check Ubuntu version
Summary
Install Rscript on Ubuntu with sudo apt install r-base from universe—Rscript lives in r-base-core at /usr/bin/Rscript. Verify with Rscript --version, run Rscript example.R, and use the full path in cron or PHP backends. Add the CRAN apt source on 22.04/24.04 LTS when you need a newer R than Ubuntu pins; interim releases should use universe or a deliberate LTS suite name—not blind $(lsb_release -cs)-cran40.

