RVM 在 ZSH 中无法工作

我想在我的 Mac 上试试 ZSH shell,但是我也做了很多 Ruby 和 Rails 的开发,所以我也经常使用 RVM。问题是我似乎不能让 RVM 在 ZSH 中工作,而且它在默认的 Bash shell 中工作得很好:

> zsh
> rvm 1.9.2
> ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
> which ruby
/usr/bin/ruby

我可以肯定地确认 RVM 已经安装,RVM 下也安装了 ruby 1.9.2; 我在 Bash 中一直在使用它。有趣的是,在 ZSH 中运行 rvm list显示了这一点:

rvm rubies


ruby-1.8.7-p302 [ x86_64 ]
=> ruby-1.9.2-p0 [ x86_64 ]

我的 iMac 和 MacBook Pro 上都出现了这种情况。我在两者上都使用 OS X 10.6.6,在 iMac 上使用 ZSH 4.3.9(在笔记本电脑上使用4.3.10)。还没有比这更好玩的了。

我试图查看 RVM 的 网站的文档,但没有任何帮助。

59906 次浏览

Do you have this line in your ~/.zshrc?

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

I use zsh, and had [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" in my .zshrc file, but was getting a parse error:404.

When I moved that line to the .profile file, the error stopped. It seems it was conflicting with something in my .zshrc file, and perhaps running it in .profile avoided the .zshrc file incompatibility. I haven't been able

Note March 2014:

With latest RVM, the following line:

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

isn't needed anymore, and it shouldn't be in your ~/.zshrc.

Documentation has been updated in RVM documentation with Zsh:

Make sure in iTerm2 Preferences: Login shell option is set (do not use Command option). This is required for RVM to work.

If you are still getting rvm is not a function errors on iTerm, try:

rvm get stable --auto-dotfiles

Note November 2014

The rvm installation instructions warn that .zshrc doesn't include $PATH when setting PATH, thus replacing PATH's contents without regard for what already exists in PATH.

To remedy this I now append PATH to have .rvm/bin and then prepend $PATH at the beginning of setting PATH on the second line:

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting


export PATH=$PATH:"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/usr/local/mysql/bin:/opt/local/bin"

I had the same problem, I solved using this after "ruby on rails" installation:

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.zshrc

and

source ~/.zshrc

I got it working on Manjaro Linux (zsh) by adding source /usr/share/rvm/scripts/rvm to $HOME/.zshrc