如何使用“RVM --default”在 MacOSX 上
使用 Ruby 和 Rails 一段时间后,我想尝试一下 RVM。一切工作正常,除了一件事:
在新打开的终端中,ruby
指向系统的 ruby,尽管事实上我使用了 rvm --default
命令。
user@terra ~ $ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
user@terra ~ $ which ruby
/opt/local/bin/ruby
user@terra ~ $ rvm list
ruby-1.8.7-p334 [ ]
=> ruby-1.9.2-p180 [ ]
在我调用 rvm reload
后一切都很好,
user@terra ~ $ rvm reload
user@terra ~ $ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.1]
tmangner@terra ~ $ which ruby
/Users/user/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
我按照文档中的描述设置了 .bash_profile
:
[[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm"
--default
似乎不起作用对我来说...
user@terra ~ $ rvm use 1.9.2 --default
Using /Users/user/.rvm/gems/ruby-1.9.2-p180
user@terra ~ $ rvm default
user@terra ~ $
我使用的是 Mac OS X Snow Leopard (10.6.6)
After using Ruby and Rails for quite some time now, I wanted to try RVM. Everything works fine, except for one thing:
In a freshly opened Terminal ruby
points to the system's ruby, despite the fact, that I used the rvm --default
command.
user@terra ~ $ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
user@terra ~ $ which ruby
/opt/local/bin/ruby
user@terra ~ $ rvm list
ruby-1.8.7-p334 [ ]
=> ruby-1.9.2-p180 [ ]
Everything is fine after I call rvm reload
user@terra ~ $ rvm reload
user@terra ~ $ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.1]
tmangner@terra ~ $ which ruby
/Users/user/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
I set up my .bash_profile
as described in the documentation:
[[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm"
That --default
does not seem to work for me ...
user@terra ~ $ rvm use 1.9.2 --default
Using /Users/user/.rvm/gems/ruby-1.9.2-p180
user@terra ~ $ rvm default
user@terra ~ $
I'm using Mac OS X Snow Leopard (10.6.6)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
我曾经遇到过同样的问题。事实证明,rvm-script 被加载了两次,这有点破坏了事情。
检查打开 shell 时加载的所有文件:
等等,并确保它们不会加载 RVM 两次。
也许把它放在
你的
~/.bash_profile
之前看看它是否发生。
I had the same problem once. It turned out the rvm-script got loaded twice, which broke things a bit.
Check all the files that load when you open a shell:
and so on, and make sure they don't load RVM twice.
Maybe put
before
in your
~/.bash_profile
to see if it happens or not.将初始化移动
到
~/.bash_profile
的底部解决了我的问题。Moving the initialization
in the bottom of
~/.bash_profile
solved the problem for me.针对 ZSH 用户的可能修复:
不知怎的,我
在 .zprofile 和 .zshrc 中都有:。
从 .zprofile 中删除该行解决了该问题。 (尽管您应该能够从其中删除任何一个,只要它只出现一次)
A possible fix for ZSH users:
Somehow I had:
in both .zprofile and .zshrc.
Removing the line from .zprofile resolved the issue. (Though you should be able to remove from either, as long as it appears just once)
而不是:
我使用了完整版本:
这在 zsh 中对我有用。
Instead of:
I used the full version:
That worked for me in zsh.
我也有同样的问题。
移动:
在 MacPorts 线路之后:
为我解决了问题。
I had the same problem.
Moving:
after the line from MacPorts:
solved the problem for me.
运行命令:
这对我在 openSUSE 上有用,但我不知道 Snow Leopard 。
Run the command:
This worked for me on openSUSE, I don't know about Snow Leopard though.
我遇到了同样的问题,因为我使用 Oh-My-Zsh ,所以有点如果我对 RVM 进行重复调用,则跟踪会更困难。
我通过将对 RVM 的调用从位于
\oh-my-zsh
内的\custom
文件夹中的单独 rvm.zsh 文件移动到我的 main 的最后来修复了这个问题.zshrc 文件。看起来 RVM 对于不在 zsh 初始化序列结束时被调用非常敏感。
I had the same problem and since I use Oh-My-Zsh it was a little bit more difficult to track if I have duplicate calls to RVM.
I fixed it by moving the call to RVM from the separate rvm.zsh file located in my
\custom
folder inside\oh-my-zsh
to the very end of my main .zshrc file.It looks like RVM is really sensitive to being called not at the end of your zsh initialization sequence.
作为健全性检查,请确保您正在处理的项目具有与您尝试在
.ruby-version
文件中设置为默认值的相同 Ruby 版本。这发生在我身上,我不明白为什么
rvm
不使用我的默认值。As a sanity check, make sure that the project you are working on has the same Ruby version that you try to set as default in the
.ruby-version
file.It happened to me, and I couldn't figure out why
rvm
doesn't use my default.我在Mac OS X 10.7上也遇到了同样的问题,后来我发现我的帐户没有添加到“rvm”组中。
将自己添加到其中后,我可以设置
--default
。I had the same issue on Mac OS X 10.7, and later I found that my account was not added to the "rvm" group.
After I added myself to it I can set
--default
.为 解决了我的问题
更改
通过在
.zshrc
文件中。显然,您需要首先确保 RVM 已正确安装,然后运行
type rvm | head -1
检查@choise 的建议。rvm use --default 1.9.3-p362
现在可以正常工作。请参阅“有时,CD 到带有 .rvmrc 的目录不会设置 Ruby 版本或宝石”了解更多信息。
My issue was resolved by changing
to
in my
.zshrc
file.Obviously, you need to make sure RVM is properly installed first, and run the
type rvm | head -1
check that @choise suggested.rvm use --default 1.9.3-p362
now works properly.See "Sometimes, CD to a dir with .rvmrc doesn't set the Ruby version or gemset" for more information.
尝试为新 shell 设置默认 Ruby:
Try this to set default Ruby for a new shell:
对于 Mac 操作系统上的一些真正的新手,请使用 JewelryBox,在首选项部分中,您会发现
选中此选项可以在红宝石之间进行切换。
您可以通过“system@*”选项选择预安装的 rubygems(如果您有 rubygems)。
For some really newbies on Mac OS use JewelryBox and in preferences section you find
checking this allow you to switch between rubies.
You can select your pre-installed rubygems (if you have rubygems) via "system@*" choice.
我遵循了上面的建议 - 检查了我的 bash_profile (这很好)并且还注意到在 ubuntu 中你可能需要遵循 https://rvm.io/support/faq/#shell_login
但是我仍然遇到这个问题,直到我意识到我尝试运行的项目有一个指定版本的 .rvmrc 文件的我没有安装的红宝石。当我纠正这个问题时 - 我不再遇到问题(所以事实上并不是使用默认值不起作用,而是这个项目覆盖了它)
I followed the suggestions above - checked my bash_profile (which was fine) and also noticed that in ubuntu you may need to head the advice of https://rvm.io/support/faq/#shell_login
However I was still having this problem until I realised that the project I was trying to run had a .rvmrc file that was specifying a version of ruby that I didn't have installed. When I corrected this - I stopped having the problem (so in fact it wasn't that the use default wasn't working, but that this project was overriding it)
我必须删除
[[ -s "/usr/local/rvm/scripts/rvm" ]] && 。 ~/.bash_profile 中的“/usr/local/rvm/scripts/rvm”
行,必须将其移动到 ~/.bashrc 的最底部。这解决了 OS X 10.10.1 上的问题。
I had to remove the
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
line from ~/.bash_profile and had to move it to the very bottom of ~/.bashrc.This fixed the issue on OS X 10.10.1.
键入 rvm | 是什么意思? head -1 打印出来?
在最新 MacOS X 上的
.bash_profile
中,我必须添加:我还创建了一个 gemset 并将其设置为默认值:
What does
type rvm | head -1
print out?In my
.bash_profile
on the latest MacOS X I had to put:I also created a gemset and set this as default:
您需要将 RVM 的路径放在 PATH 前面:
You need to put the path to RVM in front of your PATH:
由于某种原因,我的
$HOME/bin
目录中有ruby
、gem
、rake
、... 文件存根。因此我的rvm --default use 1.9.3
没有按预期工作。删除$HOME/bin
目录解决了问题。For some reason I had in my
$HOME/bin
directoryruby
,gem
,rake
, ... file stubs. Therefore myrvm --default use 1.9.3
didn't work as expected. Removing the$HOME/bin
directory solved the problem.