zsh: command not found: R on terminal using Big Sur Mac

Viewed 4326

I installed R from official cran website and i can run R from the Rstudio but when i try to use R from the terminal, I get the following results:

(base) ege@Eges-MBP ~ % R  
zsh: command not found: R
(base) ege@Eges-MBP ~ % RScript 
zsh: command not found: RScript

How can i enable the command R and run RScript from terminal on my mac?

4 Answers

This is possibly due to a bug with the current version of CRAN's R installation package (present as of version 4.0.5), that affects certain versions of Big Sur. I've answered this question here: R: command not found

In short, if running uname -r gives you a release number greater than 20, then you may need to manually create symbolic links that the package installer failed to.

In short:

    sudo -s
    mkdir -p /usr/local/bin
    cd /usr/local/bin
    rm -f R Rscript
    ln -s /Library/Frameworks/R.framework/Resources/bin/R .
    ln -s /Library/Frameworks/R.framework/Resources/bin/Rscript .

I found a way to do this.

I first found the location of R and Rscript on my disk by running R.home() on my R console. Then, i followed this guide and copied the returned location from R.home() and pasted on a new line on /etc/paths.

Then, i restarted the terminal and i was able to use R and Rscript commands

I had a similar issue. I was able to solve it by adding the below line (path obtained by running R.home() inside R) to my .zshrc. Thanks for the guidance.

export PATH="/Library/Frameworks/R.framework/Resources:${PATH}"

You need to add the directory where the R binaries are installed to the PATH environment variable.

You can add this in the current session as follows:

PATH=/usr/local/bin/:$PATH

To have this done automatically in every new session ensure that this line is added to your ~/.zshrc file:

export PATH="/usr/local/bin/:${PATH}"
Related