为什么“RVM——默认”在MacOSX上不能用?

时间:2021-08-15 12:58:38

After using Ruby and Rails for quite some time now, i wanted to try RVM. Everything works fine, except for one thing:

在使用Ruby和Rails相当长一段时间之后,我想尝试RVM。一切正常,除了一件事:

In a freshly opened Terminal ruby points to the system's ruby, despite the fact, that I used the rvm --default command.

在一个新打开的终端ruby指向系统的ruby,尽管事实是,我使用了rvm——默认命令。

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

在我调用rvm重载之后,一切正常

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've set up my .bash_profile as described in the documentation:

我已经设置了我的.bash_profile,如文档中所述:

...
[[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm" 

Thanks for your help. It is highly appreciated.

谢谢你的帮助。它是高度赞赏。

I'm using Mac OS X Snow Leopard (10.6.6)

我用的是Mac OS X雪豹(10.6.6)

Update:

更新:

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 ~ $

18 个解决方案

#1


42  

I had the same problem once. Turned out the rvm-script got loaded twice, which broke things a bit.

我曾经遇到过同样的问题。结果是rvm脚本被加载了两次,这有点破坏。

Check all the files that get loaded when you open a shell, e.g. /etc/profile, ~/.bashrc, ~/.bash_profile and so on, and make sure they don't load RVM twice.

当你打开一个shell时,检查所有加载的文件,例如/etc/profile, ~/。bashrc,(~ /。bash_profile等等,并确保它们不会加载两次RVM。

Maybe put echo "Going to load RVM" before [[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm" in your ~/.bash_profile to see if it happens or not

也许在[[-s] /用户/用户/用户/用户/之前,将echo "载入RVM"。rvm/脚本/rvm“]&&源”/用户/用户/。rvm ~ / /脚本/区”。bash_profile查看是否发生

#2


16  

Moving this:

移动:

[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"

in the bottom of ~/.bash_profile solved the problem for me.

在…的底部。bash_profile为我解决了这个问题。

#3


7  

A possible fix for ZSH users:

对ZSH用户可能的修复:

Somehow I had:

不知怎么的我:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

in both .zprofile and .zshrc.

在。zprofile和。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)

从.zprofile删除行解决了这个问题。(尽管您应该能够删除其中任何一个,只要它出现一次)

#4


6  

did you run the command rvm use --default 1.9.2?

您是否运行了rvm使用的命令——默认的1.9.2?

This worked for me on openSUSE, I don't know about snow leopard though.

这在openSUSE上对我有用,但我不知道雪豹。

#5


6  

I had the same problem. Moving the line: [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

我遇到了同样的问题。移动线:[-s "$HOME/。区/脚本/数位视讯”]]& &。“$ HOME /。rvm/scripts/rvm" # Load rvm函数

after the line from MacPorts: export PATH=/opt/local/bin:/opt/local/sbin:$PATH

从MacPorts: export PATH=/opt/local/bin:/opt/local/sbin:$PATH

solved the problem for me.

帮我解决了这个问题。

#6


5  

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.

我也有同样的问题,由于我使用Oh-My-Zsh,所以很难跟踪是否有重复的对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.

我通过将对RVM的调用从单独的RVM中移动来修复它。zsh文件位于我的\oh-my-zsh中的\自定义文件夹中,直到我的主.zshrc文件的末尾。

It looks like RVM is really sensitive to being called not at the end of your zsh initialization sequence.

看起来RVM对被调用非常敏感,而不是在zsh初始化序列的末尾。

#7


5  

Instead of:

而不是:

rvm use 1.9.2 --default 

I used the full version:

我使用了完整版:

rvm use ruby-1.9.2-p290 --default 

That worked for me in zsh.

这在zsh对我很管用。

#8


3  

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.

完整性检查——确保您正在处理的项目具有您试图在.ruby版本文件中设置为默认的ruby版本。

it happened to me, and i couldn't figure out why rvm doesn't use my default

这发生在我身上,我不明白为什么rvm不使用我的默认值

#9


2  

I had the same issue on Mac OS X 10.7.

我在Mac OS X 10.7上也有同样的问题。

And later I found that my account was not added to "rvm" group.

后来我发现我的账号没有添加到“rvm”组。

After I add myself to rvm group, I can set --default of rvm.

添加到rvm组后,我可以设置——rvm的默认值。

#10


1  

My issue was resolved by changing:

我的问题通过改变来解决:

PATH=/usr/local/bin to PATH=$PATH:/usr/local/bin in my .zshrc

PATH=/usr/local/bin to PATH=$PATH:/usr/local/bin in my .zshrc。

source @github RVM issue queue

源@github RVM发出队列

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.

显然,您需要首先确保正确安装了RVM,并运行@choise建议的类型RVM | head -1检查。rvm使用——默认的1.9.3-p362现在正常工作。

#11


0  

You need to put the path to rvm in front of your PATH

您需要将到rvm的路径放在路径前面

$ export PATH=/path/to/rvm-dir:$PATH

#12


0  

what does type rvm | head -1 print out?

什么类型的rvm |头-1打印出来?

in my bash_profile (on the latest osx) i had to put

在我的bash_profile(在最新的osx上)中,我必须放入

# Ruby Version Manager
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"

i also created a gemset and setted this as default:

我还创建了一个gemset并将其设置为默认值:

rvm reload
rvm install 1.9.2
rvm --create use 1.9.2@default
rvm --default use 1.9.2@default

#13


0  

same pb here. line was there twice and it broke it.... for whatever reason... removing the extraneous line solved it

相同的pb。线有两次,它打破了....无论什么原因……去掉多余的线就解决了这个问题

#14


0  

For some reason I had in my $HOME/bin directory ruby, gem, rake, ... file stubs. An example below. Therefore my rvm --default use 1.9.3 didn't work as expected. Removing the $HOME/bin directory solved the problem.

出于某种原因,我在$HOME/bin目录ruby、gem、rake……文件存根。下面的一个例子。因此,我的rvm -默认使用1.9.3没有像预期的那样工作。删除$HOME/bin目录解决了这个问题。

cat  bin/ruby 
#!/usr/bin/env bash

if [[ -s "/usr/local/rvm/environments/ruby-1.9.2-p290" ]]
then
  source "/usr/local/rvm/environments/ruby-1.9.2-p290"
  exec ruby "$@"
else
  echo "ERROR: Missing RVM environment file: '/usr/local/rvm/environments/ruby-1.9.2-p290'" >&2
  exit 1
fi

#15


0  

Try this to set default ruby for new shell:

尝试设置新shell的默认ruby:

sudo rvm alias create default 1.9.2

#16


0  

For some really newbies on Mac OS use JewelryBox and in preferences section you find

对于一些真正的新手,在Mac OS上使用珠宝盒和在偏好部分你找到。

"show default ruby in system menu bar"

checking this allow you to switch between rubies.

检查这个可以让你在红宝石之间切换。

You can select your pre-installed rubygems (if you have rubygems) via "system@*" choice.

您可以通过“system@*”选项选择预先安装的rubygems(如果您有rubygems)。

#17


0  

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

我遵循了上面的建议——检查了bash_profile(这很好),并注意到在ubuntu中,您可能需要获得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)

然而,直到我意识到我要运行的项目有一个名为.rvmrc的文件,它指定了一个我没有安装的ruby版本时,我仍然有这个问题。当我纠正这个错误时——我停止了这个问题(所以实际上并不是使用默认值不起作用,而是这个项目重写了它)

#18


0  

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.

我必须删除[[-s "/usr/local/rvm/scripts/rvm"]和&。“/ usr /地方/区/脚本/数位视讯”从~ /线。bash_profile必须移动到~/.bashrc的最底部。

This fixed the issue on OS X 10.10.1.

这解决了OS X 10.10.1上的问题。

#1


42  

I had the same problem once. Turned out the rvm-script got loaded twice, which broke things a bit.

我曾经遇到过同样的问题。结果是rvm脚本被加载了两次,这有点破坏。

Check all the files that get loaded when you open a shell, e.g. /etc/profile, ~/.bashrc, ~/.bash_profile and so on, and make sure they don't load RVM twice.

当你打开一个shell时,检查所有加载的文件,例如/etc/profile, ~/。bashrc,(~ /。bash_profile等等,并确保它们不会加载两次RVM。

Maybe put echo "Going to load RVM" before [[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm" in your ~/.bash_profile to see if it happens or not

也许在[[-s] /用户/用户/用户/用户/之前,将echo "载入RVM"。rvm/脚本/rvm“]&&源”/用户/用户/。rvm ~ / /脚本/区”。bash_profile查看是否发生

#2


16  

Moving this:

移动:

[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"

in the bottom of ~/.bash_profile solved the problem for me.

在…的底部。bash_profile为我解决了这个问题。

#3


7  

A possible fix for ZSH users:

对ZSH用户可能的修复:

Somehow I had:

不知怎么的我:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

in both .zprofile and .zshrc.

在。zprofile和。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)

从.zprofile删除行解决了这个问题。(尽管您应该能够删除其中任何一个,只要它出现一次)

#4


6  

did you run the command rvm use --default 1.9.2?

您是否运行了rvm使用的命令——默认的1.9.2?

This worked for me on openSUSE, I don't know about snow leopard though.

这在openSUSE上对我有用,但我不知道雪豹。

#5


6  

I had the same problem. Moving the line: [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

我遇到了同样的问题。移动线:[-s "$HOME/。区/脚本/数位视讯”]]& &。“$ HOME /。rvm/scripts/rvm" # Load rvm函数

after the line from MacPorts: export PATH=/opt/local/bin:/opt/local/sbin:$PATH

从MacPorts: export PATH=/opt/local/bin:/opt/local/sbin:$PATH

solved the problem for me.

帮我解决了这个问题。

#6


5  

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.

我也有同样的问题,由于我使用Oh-My-Zsh,所以很难跟踪是否有重复的对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.

我通过将对RVM的调用从单独的RVM中移动来修复它。zsh文件位于我的\oh-my-zsh中的\自定义文件夹中,直到我的主.zshrc文件的末尾。

It looks like RVM is really sensitive to being called not at the end of your zsh initialization sequence.

看起来RVM对被调用非常敏感,而不是在zsh初始化序列的末尾。

#7


5  

Instead of:

而不是:

rvm use 1.9.2 --default 

I used the full version:

我使用了完整版:

rvm use ruby-1.9.2-p290 --default 

That worked for me in zsh.

这在zsh对我很管用。

#8


3  

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.

完整性检查——确保您正在处理的项目具有您试图在.ruby版本文件中设置为默认的ruby版本。

it happened to me, and i couldn't figure out why rvm doesn't use my default

这发生在我身上,我不明白为什么rvm不使用我的默认值

#9


2  

I had the same issue on Mac OS X 10.7.

我在Mac OS X 10.7上也有同样的问题。

And later I found that my account was not added to "rvm" group.

后来我发现我的账号没有添加到“rvm”组。

After I add myself to rvm group, I can set --default of rvm.

添加到rvm组后,我可以设置——rvm的默认值。

#10


1  

My issue was resolved by changing:

我的问题通过改变来解决:

PATH=/usr/local/bin to PATH=$PATH:/usr/local/bin in my .zshrc

PATH=/usr/local/bin to PATH=$PATH:/usr/local/bin in my .zshrc。

source @github RVM issue queue

源@github RVM发出队列

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.

显然,您需要首先确保正确安装了RVM,并运行@choise建议的类型RVM | head -1检查。rvm使用——默认的1.9.3-p362现在正常工作。

#11


0  

You need to put the path to rvm in front of your PATH

您需要将到rvm的路径放在路径前面

$ export PATH=/path/to/rvm-dir:$PATH

#12


0  

what does type rvm | head -1 print out?

什么类型的rvm |头-1打印出来?

in my bash_profile (on the latest osx) i had to put

在我的bash_profile(在最新的osx上)中,我必须放入

# Ruby Version Manager
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"

i also created a gemset and setted this as default:

我还创建了一个gemset并将其设置为默认值:

rvm reload
rvm install 1.9.2
rvm --create use 1.9.2@default
rvm --default use 1.9.2@default

#13


0  

same pb here. line was there twice and it broke it.... for whatever reason... removing the extraneous line solved it

相同的pb。线有两次,它打破了....无论什么原因……去掉多余的线就解决了这个问题

#14


0  

For some reason I had in my $HOME/bin directory ruby, gem, rake, ... file stubs. An example below. Therefore my rvm --default use 1.9.3 didn't work as expected. Removing the $HOME/bin directory solved the problem.

出于某种原因,我在$HOME/bin目录ruby、gem、rake……文件存根。下面的一个例子。因此,我的rvm -默认使用1.9.3没有像预期的那样工作。删除$HOME/bin目录解决了这个问题。

cat  bin/ruby 
#!/usr/bin/env bash

if [[ -s "/usr/local/rvm/environments/ruby-1.9.2-p290" ]]
then
  source "/usr/local/rvm/environments/ruby-1.9.2-p290"
  exec ruby "$@"
else
  echo "ERROR: Missing RVM environment file: '/usr/local/rvm/environments/ruby-1.9.2-p290'" >&2
  exit 1
fi

#15


0  

Try this to set default ruby for new shell:

尝试设置新shell的默认ruby:

sudo rvm alias create default 1.9.2

#16


0  

For some really newbies on Mac OS use JewelryBox and in preferences section you find

对于一些真正的新手,在Mac OS上使用珠宝盒和在偏好部分你找到。

"show default ruby in system menu bar"

checking this allow you to switch between rubies.

检查这个可以让你在红宝石之间切换。

You can select your pre-installed rubygems (if you have rubygems) via "system@*" choice.

您可以通过“system@*”选项选择预先安装的rubygems(如果您有rubygems)。

#17


0  

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

我遵循了上面的建议——检查了bash_profile(这很好),并注意到在ubuntu中,您可能需要获得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)

然而,直到我意识到我要运行的项目有一个名为.rvmrc的文件,它指定了一个我没有安装的ruby版本时,我仍然有这个问题。当我纠正这个错误时——我停止了这个问题(所以实际上并不是使用默认值不起作用,而是这个项目重写了它)

#18


0  

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.

我必须删除[[-s "/usr/local/rvm/scripts/rvm"]和&。“/ usr /地方/区/脚本/数位视讯”从~ /线。bash_profile必须移动到~/.bashrc的最底部。

This fixed the issue on OS X 10.10.1.

这解决了OS X 10.10.1上的问题。