Why doesn't “RVM --default” work for me on Mac

2019-01-10 21:09发布

问题:

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

...
[[ -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)

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

回答1:

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

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.

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



回答2:

Moving this:

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

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



回答3:

A possible fix for ZSH users:

Somehow I had:

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

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)



回答4:

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

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



回答5:

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

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

solved the problem for me.



回答6:

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.



回答7:

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.



回答8:

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



回答9:

I had the same issue on Mac OS X 10.7.

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

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



回答10:

My issue was resolved by changing:

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

source @github RVM issue queue

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.



回答11:

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

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


回答12:

what does type rvm | head -1 print out?

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

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

i also created a gemset and setted this as default:

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


回答13:

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



回答14:

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.

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:

Try this to set default ruby for new shell:

sudo rvm alias create default 1.9.2


回答16:

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

"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.



回答17:

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)



回答18:

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.



标签: ruby macos rvm