默认情况下调用旧版本时从终端运行新版本的 R [英] Running newer version of R from terminal when older version is invoked by default
问题描述
我正在尝试在 OSX 计算机 (OSX 10.11.6) 上从 iTerm 运行 R.当我输入 R
时,它会从路径 /Users/***/miniconda2/bin/R
打开旧版本的 R.我希望它默认运行在 /usr/local/bin/R
中找到的 R 版本,而不必每次都输入完整路径.如何更改默认 R 的位置?
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?
感谢您的帮助
推荐答案
这可能是由于 PATH
变量优先于 ~/miniconda2/bin
在 /usr/local/bin
.我在这里为您提供了一些选项,以帮助您了解发生这种情况的原因.
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.
假设您的 PATH
如下所示:
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
您可以修改 PATH
以将 /Users/me/miniconda2/bin
移动到 /usr/local/bin
之后或从 /usr/local/bin
中删除它code>PATH 完全.缺点是如果您依赖 ~/miniconda2/bin
中的其他二进制文件,则在按名称执行它们时将不再找到它们.
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.
另一种选择是将 ~/miniconda/bin/R
移开,例如使用
Another option would be to move ~/miniconda/bin/R
out of the way, for example using
mv ~/miniconda/bin/R ~/miniconda/bin/R-miniconda
之后 R 将从 $PATH
中的下一个位置运行,但如果您更新 miniconda2,它可能会返回.
Afterwards R will be run from the next location in $PATH
, but if you update miniconda2 it may return.
最后,您可以确保在 $PATH
更远的地方有一个 R 可执行文件.这可能是最简单、最有效的选择.
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.
首先,确保您的主目录中有一个 bin
文件夹.如果不是这种情况,请使用 mkdir ~/bin
创建它,然后重新启动终端.重新启动应该会导致 ~/.profile
中的代码将该文件夹添加到您的 $PATH
.您可以通过执行 echo $PATH
进行验证.如果不是这种情况,请将以下行添加到您的 ~/.profile
或 ~/.bash_profile
:
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
在顶部的示例中,PATH
已经在行首(最高优先级)包含 /Users/me/bin
.
In the example at the top, the PATH
already contains /Users/me/bin
at the beginning of the line (highest priority).
接下来,在新创建的文件夹中创建一个指向 R 二进制文件的软链接:
Next, create a soft link to the R binary in the newly created folder:
ln -s /usr/local/bin/R ~/bin/R
您现在应该能够执行 R,它会更喜欢创建的软链接,它将执行您喜欢的软链接.如果它不能立即工作,请执行 hash -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.
这篇关于默认情况下调用旧版本时从终端运行新版本的 R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!