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

孤街醉人 提交于 2020-01-06 15:08:53

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/38737621/running-newer-version-of-r-from-terminal-when-older-version-is-invoked-by-defaul

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!