sacuL
sacuL

Reputation: 51335

Running newer version of R from terminal when older version is invoked by default

I'm trying to run R from iTerm on an OSX computer (OSX 10.11.6). When I enter R, it opens up an older version of R, from the path /Users/***/miniconda2/bin/R. I would like it to run, by default, an R version found at /usr/local/bin/R, without having to enter the full path every time. How would one go about changing the location of the default R?

Thanks for your help

Upvotes: 2

Views: 2107

Answers (2)

Ted M.
Ted M.

Reputation: 392

Just in case you happen to be using RStudio Server (open source) or someone is looking for how to change the RStudio Server default version of R, here is what I found when trying to answer the same question:

Starting in RStudio Server 1.3 (the newest version is 1.4.1106, released February 22, 2021), a user’s preferred version of R can be specified in the rstudio-prefs.json file in the global-level /etc/rstudio folder or in the user-level ~/.config/rstudio folder.

See https://blog.rstudio.com/2020/02/18/rstudio-1-3-preview-configuration/ and https://docs.rstudio.com/ide/server-pro/session-user-settings.html for user setting options in newer versions of RStudio Server.

See https://support.rstudio.com/hc/en-us/articles/200716783-RStudio-Release-History for RStudio release history and https://www.rstudio.com/products/rstudio/download-server/redhat-centos/ for Red Hat downloads of the newest version of RStudio Server.

Upvotes: 1

Philipp Kewisch
Philipp Kewisch

Reputation: 992

This is likely due to the PATH variable preferring ~/miniconda2/bin before /usr/local/bin. I'm giving you a few options here to help understand why it is happening.

Let's assume your PATH looks like this:

/Users/me/bin:/Users/me/miniconda2/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Modify PATH

You could modify PATH to move /Users/me/miniconda2/bin after /usr/local/bin or remove it from PATH completely. The downside is that if you rely on other binaries in ~/miniconda2/bin they will no longer be found when executing them by name.

Move R out of the way

Another option would be to move ~/miniconda/bin/R out of the way, for example using

mv ~/miniconda/bin/R ~/miniconda/bin/R-miniconda

Afterwards R will be run from the next location in $PATH, but if you update miniconda2 it may return.

Link to R further up in the PATH (easiest/best)

Finally, you could make sure that there is an R executable in something that is further up the $PATH. This is probably the easiest and most effective option.

First, make sure you have a bin folder in your home directory. If this is not the case, create it using mkdir ~/bin and then restart the terminal. The restart should cause the code in ~/.profile to add that folder to your $PATH. You can verify by doing echo $PATH. If this is not the case, add the following line to your ~/.profile or ~/.bash_profile:

export PATH=$HOME/bin:$PATH

In the example at the top, the PATH already contains /Users/me/bin at the beginning of the line (highest priority).

Next, create a soft link to the R binary in the newly created folder:

ln -s /usr/local/bin/R ~/bin/R

You should now be able to execute R, which will prefer the softlink created, which will execute the one you like. If it does not work right away execute hash -r or restart the terminal.

Upvotes: 3

Related Questions