简体   繁体   English

如何在 MacOSX 上使用“RVM --default”

[英]How to use "RVM --default" on MacOSX

After using Ruby and Rails for quite some time now, I wanted to try RVM.在使用 Ruby 和 Rails 一段时间后,我想尝试 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.在新打开的终端中, 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 [ ]

Everything is fine after I call rvm reload调用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:我按照文档中的描述设置了我的.bash_profile

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

That --default does not seem to work for me ...--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 ~ $

I'm using Mac OS X Snow Leopard (10.6.6)我使用的是 Mac OS X Snow Leopard (10.6.6)

I had the same problem once.我曾经遇到过同样的问题。 It turned out the rvm-script got loaded twice, which broke things a bit.结果是 rvm-script 被加载了两次,这有点破坏了。

Check all the files that load when you open a shell:检查打开 shell 时加载的所有文件:

/etc/profile
~/.bashrc
~/.bash_profile

and so on, and make sure they don't load RVM twice.等等,并确保它们不会加载 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.在您的~/.bash_profile中查看它是否发生。

Moving the initialization移动初始化

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

in the bottom of ~/.bash_profile solved the problem for me.~/.bash_profile的底部为我解决了这个问题。

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.从 .zprofile 中删除该行解决了该问题。 (Though you should be able to remove from either, as long as it appears just once) (尽管您应该能够从中删除,只要它只出现一次)

Run the command:运行命令:

rvm use --default 1.9.2?

This worked for me on openSUSE, I don't know about Snow Leopard though.这在 openSUSE 上对我有用,但我不知道 Snow Leopard。

I had the same problem.我有同样的问题。

Moving:移动:

 [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

after the line from MacPorts:在 MacPorts 之后:

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

solved the problem for me.为我解决了这个问题。

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.我通过将调用从位于\\oh-my-zsh内的\\oh-my-zsh \\custom文件夹中的单独 rvm.zsh 文件移动到我的主 .zshrc 文件的末尾来修复它。

It looks like RVM is really sensitive to being called not at the end of your zsh initialization sequence.看起来 RVM 对不在 zsh 初始化序列结束时被调用非常敏感。

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 中对我有用。

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.作为完整性检查,请确保您正在处理的项目与您尝试在.ruby-version文件中设置为默认值的 Ruby 版本相同。

It happened to me, and I couldn't figure out why rvm doesn't use my default.它发生在我身上,我无法弄清楚为什么rvm不使用我的默认值。

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.我在 Mac OS X 10.7 上遇到了同样的问题,后来我发现我的帐户没有添加到“rvm”组中。

After I added myself to it I can set --default .在我添加自己之后,我可以设置--default

My issue was resolved by changing我的问题已通过更改解决

PATH=/usr/local/bin

to

PATH=$PATH:/usr/local/bin

in my .zshrc file.在我的.zshrc文件中。

Obviously, you need to make sure RVM is properly installed first, and run the type rvm | head -1显然,您首先需要确保正确安装了 RVM,然后运行type rvm | head -1 type rvm | head -1 check that @choise suggested. type rvm | head -1检查@choise 建议的内容。 rvm use --default 1.9.3-p362 now works properly. rvm use --default 1.9.3-p362现在可以正常工作。

See " Sometimes, CD to a dir with .rvmrc doesn't set the Ruby version or gemset " for more information.有关更多信息请参阅“ 有时,CD 到带有 .rvmrc 的目录不会设置 Ruby 版本或 gemset ”。

试试这个来为新的 shell 设置默认的 Ruby:

sudo rvm alias create default 1.9.2

For some really newbies on Mac OS use JewelryBox and in preferences section you find对于 Mac OS 上的一些真正的新手,请使用 JewelryBox 并在首选项部分找到

"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@*”选项来选择您预先安装的 ruby​​gems(如果您有 ruby​​gems)。

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.但是,我仍然遇到这个问题,直到我意识到我尝试运行的项目有一个 .rvmrc 文件,该文件指定了我尚未安装的 ruby​​ 版本。 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)当我纠正这个问题时 - 我不再遇到这个问题(所以实际上并不是使用默认值不起作用,而是这个项目覆盖了它)

I had to remove the [[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"我不得不删除[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" [[ -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.来自 ~/.bash_profile 的[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"行,必须将其移动到 ~/.bashrc 的最底部。

This fixed the issue on OS X 10.10.1.这解决了 OS X 10.10.1 上的问题。

您需要将 RVM 的路径放在 PATH 前面:

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

What does type rvm | head -1什么type rvm | head -1 type rvm | head -1 print out? type rvm | head -1打印出来?

In my .bash_profile on the latest MacOS XI had to put:在我最新的 MacOS XI 上的.bash_profile ,必须输入:

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

I also created a gemset and set 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

For some reason I had in my $HOME/bin directory ruby , gem , rake , ... file stubs.出于某种原因,我的$HOME/bin目录中有rubygemrake , ... 文件存根。 Therefore my rvm --default use 1.9.3 didn't work as expected.因此我的rvm --default use 1.9.3没有按预期工作。 Removing the $HOME/bin directory solved the problem.删除$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

same pb here. 同样的铅在这里。 line was there twice and it broke it.... for whatever reason... removing the extraneous line solved it 线在那儿有两次,它把它弄坏了。。。。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM