R: Command Not Found | Fix PATH And Launch R Fast

“R: command not found” means your shell can’t find the R program; install R or add it to your PATH, then reopen your terminal.

You typed R, hit Enter, and the terminal answered with a blunt error. It feels like your machine is refusing to run R at all. Most of the time, it’s simpler. Your shell is searching a list of folders for an executable named R. If that list doesn’t include the folder where R lives, you get the message.

This guide helps you get R launching from the terminal on macOS, Windows, and Linux, plus a few extra checks for scripts and editors. You’ll see fast tests first, then clean, durable fixes you can keep.

What The Message Means And What It Does Not

The terminal isn’t judging your code. It’s failing before your code even starts. “Command not found” means the shell can’t locate a program with that name in any folder listed in your PATH. That list is just a set of directories separated by colons on macOS and Linux, or semicolons on Windows.

There are three common root causes. R isn’t installed. R is installed, but the folder that contains R is not on PATH. Or you installed a new R, then your terminal is still using old shell settings until you restart it.

One more detail helps. On many systems there are two related commands: R starts an interactive session, while Rscript runs a file. You can have one working and the other missing, depending on how the install was done and which folders are on PATH. The R manual shows the standard use of Rscript, R CMD BATCH, and related commands. Read the R manual section.

Fast Checks That Tell You What’s Broken

Do these checks in order. They take a minute and stop you from guessing.

  1. Try the exact binary name — Type R and then Rscript. If one works, you already know the install exists and the gap is just your path setup.
  2. Ask the shell to locate R — Run which R on macOS or Linux, or where R on Windows. An empty result means the shell can’t see it.
  3. Print your PATH list — Run echo $PATH on macOS or Linux, or echo %PATH% on Windows. You’re looking for the folder that contains the R executable.
  4. Search known install spots — On macOS, check /usr/local/bin and /opt/homebrew/bin. On Ubuntu, check /usr/bin. On Windows, check C:\Program Files\R\R-4.x.x\bin.
  5. Confirm the app exists — If you use RStudio, open it and check the R version it reports. If RStudio says R isn’t installed, the issue is bigger than PATH.

If you want one quick decision rule, use this. If your computer can open R from a desktop app but your terminal can’t, R is installed and your terminal path is the missing piece. That’s the pattern many macOS users hit. A Superuser thread shows that exact scenario.

R: Command Not Found On macOS

On macOS, the most common reason is a path mismatch. The R app can be present in /Applications, while the command line launcher is not linked into a folder on PATH. Intel Macs and Apple Silicon Macs can also differ because Homebrew uses different base folders.

Install R The Clean Way

If you’re not sure R is installed, install from the official CRAN macOS page. It stays current and matches how most tools expect R to be laid out. Get R for macOS from CRAN.

Add R To Your PATH

After install, you want the folder that contains the R executable on your PATH. Many setups place command line links in /usr/local/bin, which is often already on PATH. If your terminal can’t find it, add the directory in your shell config file, then restart your terminal.

  1. Find where R lives — Run ls -l /usr/local/bin/R and ls -l /opt/homebrew/bin/R. One may exist as a link pointing into the R install folder.
  2. Edit your shell config — For zsh, edit ~/.zshrc. For bash, edit ~/.bash_profile or ~/.bashrc, depending on your setup.
  3. Add a PATH line — Add a line like export PATH="$PATH:/usr/local/bin" if that folder is missing from your path printout.
  4. Restart the terminal — Close the app fully and reopen it. A new tab is sometimes not enough if the shell keeps a cached path.

If that still fails, don’t fight the shell. You can run the app directly with open -a R as a quick sanity check, then return to fixing the path link. That pattern is described in the macOS thread above.

Fixing R Command Not Found Errors In Windows Terminals

Windows has two common places this error shows up: the classic Command Prompt or PowerShell, and Git Bash or WSL. The fix is usually the same idea: make sure the R bin folder is on your system path.

Check The Install Folder

Most R installs land under C:\Program Files\R. Inside, look for a versioned folder like R-4.4.0, then a bin folder. That bin folder contains R.exe and Rscript.exe.

Add The Bin Folder To PATH

You can add it using Windows Settings, or you can test it first by calling the full path once. If calling the full path works, adding it to PATH is the durable fix. A Stack Overflow answer for the similar Rscript message points straight at that bin-folder path step. See the Rscript path note.

  1. Copy the bin path — Copy the full folder path, such as C:\Program Files\R\R-4.4.0\bin.
  2. Open Path settings — Search Windows for “Edit system variables”, then open the Path list under user variables.
  3. Add the folder — Paste the bin path as a new entry and save.
  4. Restart your terminal — Close and reopen Command Prompt or PowerShell so it reloads the path list.

Git Bash And WSL Notes

Git Bash uses a Unix-like shell on top of Windows. It can miss Windows PATH updates until you restart it. WSL runs a Linux layer, so it will not see Windows-installed R unless you explicitly link to the Windows binary. In WSL, it’s usually cleaner to install R inside WSL using your Linux package manager.

Fixes For Linux And Shared Servers

On Linux, R is often installed from the distro repo, so /usr/bin/R exists and the terminal sees it right away. If you installed from a tarball or a custom location, you might end up with R under /usr/local/bin, which some minimal shells don’t include in their path list.

A Linux thread on Stack Overflow calls out the most direct fix: add /usr/local/bin to PATH when that’s where R was placed. Read the /usr/local/bin path answer.

Install From Your Distro Repo

If you want a low-friction install on Ubuntu, use the CRAN instructions for Ubuntu. They spell out which packages to install and where system libraries go. Use the Ubuntu CRAN README.

Add A Custom Install Location To PATH

If you already have R installed and you just need the terminal to find it, add the folder that holds the R binary to your shell config file, then restart your session. The right file depends on your shell and how you log in.

  1. Locate the binary — Run command -v R and command -v Rscript. If they return nothing, search with find / -name R -type f 2>/dev/null if you have permission.
  2. Pick the config file — For bash, use ~/.bashrc. For zsh, use ~/.zshrc. For login shells on some systems, ~/.profile can matter.
  3. Add the folder — Add something like export PATH="$PATH:/usr/local/bin", swapping in the actual folder you found.
  4. Reload or relog — Run source ~/.bashrc or open a new session.

Multi-User Systems And Modules

On shared servers, R can be provided through a modules system. In that case, you load the module first, then R appears on your path list. If you run R before loading the module, you’ll see the same error.

When The Error Shows Up In Scripts And Editors

Sometimes R runs fine in an interactive terminal, yet a script, scheduler, or editor claims it can’t find it. That’s usually because the tool starts a non-interactive shell with a different path list. You fix it either by ensuring the tool inherits the same path, or by calling R with a full path.

Prefer Rscript For Files

If you’re running a file, call Rscript instead of starting an interactive R session. The R manual shows the normal pattern: Rscript my_script.R and R CMD BATCH for batch runs. Read the R manual section.

Use A Full Path In Scheduled Jobs

Cron jobs and some job runners start with a tiny path list. If which Rscript prints /usr/local/bin/Rscript in your interactive shell, use that full path in the job. A Unix Stack Exchange answer notes that a full path can be the simplest fix when path edits don’t apply to the runner. Read the full-path tip.

Spot The Most Common Patterns Fast

This table maps the message you see to the fastest next step. Keep it near your terminal while you test.

What You See Likely Cause Fast Fix
r: command not found R not on PATH Add the R bin folder to PATH, restart terminal
Rscript: command not found Rscript not on PATH Find Rscript with command -v, use full path or edit PATH
R runs in RStudio, not in terminal Terminal PATH missing install link Add /usr/local/bin or the correct link folder to PATH
Works in one terminal, fails in another Different shell config files Update the right rc file for that shell, reopen

A Final Checklist You Can Run In Two Minutes

  1. Confirm the program exists — Open R or RStudio once, then close it, so you know the install is real.
  2. Check the command lookup — Run which R or where R and note the result.
  3. Check the script runner — Run which Rscript and test Rscript -e "1+1".
  4. Fix the path once — Add the correct folder to your shell config or Windows Path list.
  5. Restart and retest — Close the terminal fully, reopen, and run R --version.

If you still see r: command not found after these steps, the fastest way forward is to locate the real binary path, run it once by full path, then adjust your path list to match. That keeps the fix grounded in what’s on your disk, not guesses.

If you share a machine, write down how you installed R, where the R binary sits, and which shell you use. Those details save time when this error pops up after an update on your laptop.