sacul sacul - 1 year ago 101
R Question

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

, it opens up an older version of R, from the path
. I would like it to run, by default, an R version found at
, 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

Answer Source

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:


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 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. In the above example the path already contains /Users/me/bin at the very top.

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download