RVM is not working in ZSH
Asked Answered
P

6

102

I'd like to try out the ZSH shell on my Mac, but I also do a lot of Ruby and Rails development, so I use RVM quite a bit too. The problem is that I can't seem to get RVM to work in ZSH, and it's working fine in the default 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

I can definitely confirm that RVM is installed, as well as ruby 1.9.2 under RVM; I use it all the time in Bash. Running an rvm list in ZSH shows this, interestingly:

rvm rubies

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

This is happening on both my iMac and MacBook Pro. I am using OS X 10.6.6 on both, ZSH 4.3.9 on the iMac (4.3.10 on the laptop). Nothing fancy like oh-my-zsh just yet.

I tried looking at the documentation on RVM's website, but nothing helped me there.

Plyler answered 21/1, 2011 at 4:58 Comment(0)
C
300

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

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" 
Cowden answered 21/1, 2011 at 5:24 Comment(9)
Hahaha, totally forgot about that simple thing. Now I'm annoyed at my stubbornness for not coming here sooner. Thank you :).Plyler
You are welcome. It happens sometime :) One useful thing I did to keep my old settings: "source ~/.profile" and "source ~/.bash_profile" in my ~/.zshrc . It also keep my .zshrc a bit cleaner.Cowden
I found when I used oh-my-zsh to customise zsh it added a bunch of paths to .zshrc that it took from my existing shell -- this included paths added by rvm under bash.Moriarty
@Cowden Do I still need PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting in .zshrc?Eruptive
I spent ages trying to figure this out too, as the line [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" is in my .zlogin, but I suppose it wasn't using it when opening new terminal windows on my mac (10.7.3, oh my zsh). Adding it to the .zshrc worked for me too but according to this stackoverflow comment, .zshrc is the wrong place to put this??Verbalize
Also, make sure that your path to $HOME/.rvm/bin is before /usr/bin, otherwise you might be calling the the Ruby executable that comes with OS X. You can check the precedence by typing 'where ruby' in ZSH.Gertrudgertruda
Based on all the votes, I'm kinda glad to see that other people miss simple things like me :)Plyler
For a global rvm install - [[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" Dirac
@PerishableDave That was exactly the problem here. I had to add it before /usr/bin because it was too late.Drivel
G
25

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
Gobbledegook answered 2/3, 2014 at 23:10 Comment(1)
At least on my install of Arch Linux, the xterm doesn't use a login shell and thus rvm doesn't seem to be set up correctly, even running that command.Prolific
O
4

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"
Oligosaccharide answered 29/11, 2014 at 15:54 Comment(0)
M
2

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
Mcinnis answered 3/9, 2017 at 23:29 Comment(0)
H
1

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

Hogen answered 19/10, 2013 at 7:40 Comment(0)
A
1

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

Alfi answered 4/10, 2021 at 16:40 Comment(1)
Thank you Alexanderius! My path was not "$HOME/.rvm/scripts/rvm" as previous versions. Adding source /usr/share/rvm/scripts/rvm to .zshrc worked for me on Ubuntu 20.04.Recuperative

© 2022 - 2024 — McMap. All rights reserved.