Can't change Ruby Version using RVM - ruby

I'm running Lion DP4 with Ruby 1.8.7 preinstalled. For my new project I need the latest Ruby version though. Therefore installed rvm and the latest Ruby. Somehow when I try to use the new version it doesn't give me any errors, but the change just doesn't take effect.
~martin$ rvm use ruby 1.9.2 --default
Using /Users/martin/.rvm/gems/ruby-1.9.2-p180
~martin$ which ruby
/usr/bin/ruby
My .bash_profile file looks like this:
export PATH="/opt/local/bin"
export PATH="/opt/local/sbin"
export PATH="/usr/texbin:${PATH}"
export PATH=$PATH:/Users/martin/bin
export PATH=$PATH:/usr/local/mysql/bin
source ~/.git-completion.bash
alias mysql '/usr/local/mysql/bin/mysql'
alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
Can anyone tell me why me wanting to change the Ruby version is not working? Appreciate any help.
Thanks in advance!
Martin
EDIT (2011/06/28 - 1:08PM):
Ok, for some really odd reason everything works now.
I guess my .bash_profile file somehow was messed up. In the beginning I thought that I installed it as root therefore changed the rvm path to
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" # Load RVM function
But I guess my path declaration in general was totally messed up. Now my .bash_profile file looks like this:
export PATH=$PATH:/opt/local/bin
export PATH=$PATH:/opt/local/sbin
export PATH=$PATH:/usr/texbin
export PATH=$PATH:/Users/martin/bin
export PATH=$PATH:/usr/local/mysql/bin
source ~/.git-completion.bash
alias mysql '/usr/local/mysql/bin/mysql'
alias mysqladmin '/usr/local/mysql/bin/mysqladmin'
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" # Load RVM function
#Mark
Yes, I installed Ruby using MacPorts and hope that now I've fixed the path.

I had the same problem, this is not a real solution but a hack:
sudo mv /usr/bin/ruby /usr/bin/_ruby
Note that this is not ideal since it might break scripts that start with:
#!/usr/bin/ruby
blablabla
Looking forward for a better answer in the meantime :)

Related

Need to Fix PATH in my bashrc File for RVM

I did a clean install of my operating system recently and copied my old .bashrc file from a backup. I installed rvm version 1.26.10 (latest stable version). I installed ruby 2.2.0. When I source the .bashrc file I get the following error:
Warning! PATH is not properly set up, '/Users/myusername/.rvm/gems/ruby-2.2.0#mygemset/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-2.2.0#mygemset'.
Here are my PATH statements. The first line I included here is one that was in the new install of RVM in the .bash_profile file. I copied them into .bashrc. I'm also running postgres.app which requires the last statement in order to set it as the current PostgreSQL instance.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
export PATH="$PATH:$HOME/.rvm/bin"
export PATH=/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH
I started with the .bashrc file recommended by the Ruby on Rails Tutorial by Michael Hartl (the version current in 2011 or 2012) and the settings used by RVM back then. I know things have changed a bit since then.
My bash knowledge is limited so any help would be appreciated.
UPDATE: 2/2/2015 2:40 pm CST
I changed my bash statements to the following and got rid of the warning:
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
UPDATE: 2/2/2015 5:14 pm CST
Here are my Bash statements:
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql"
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Here is the output for echo $PATH:
/Users/username/.rvm/gems/ruby-2.2.0#gemsetname/bin:/Users/username/.rvm/gems/ruby-2.2.0#global/bin:/Users/username/.rvm/rubies/ruby-2.2.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Server.app/Contents/ServerRoot/usr/bin:/Applications/Server.app/Contents/ServerRoot/usr/sbin:/Users/username/.rvm/bin:/Users/username:/.rvm/rubies/ruby-2.2.0/bin/ruby:/Applications/Postgres.app/Contents/Versions/9.4/bin:/usr/bin/psql:/Users/username/.rvm/bin
My RVM wouldn't stop complaining about PATH even though the last thing in my .bashrc was this line:
# RVM
source ~/.rvm/scripts/rvm
So I just redirected the complaining to /dev/null:
# RVM
source ~/.rvm/scripts/rvm > /dev/null 2>&1
rvm use default > /dev/null 2>&1
The last line also makes sure RVM is first in PATH, so it doesn't really have anything to complain about.
rvm expects its $PATH stuff to come first in $PATH. You should add items to the $PATH before sourcing rvm, not after.
After dealing with this for several days I decided to go ahead and continue to proceed with my implementation of postgres.app with the warning message I got with RVM. I ran my original bash statements in a different order.
export PATH="$PATH:$HOME/.rvm/bin"
PATH="$PATH:$HOME:/.rvm/rubies/ruby-2.2.0/bin/ruby:/usr/bin/psql:/usr/local:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export PATH=/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH
I was successful in implementing postgres.app. I still get the warning message but my Ruby on Rails applications are able to find the correct gems and run successfully.
You should add the line like this
export PATH= '/Users/myusername/.rvm/gems/ruby-2.2.0#mygemset/bin:other"
Maybe that can help you

RVM Ruby installation not successful

I'm trying to install ruby using rvm on linux debian. This is my problem:
Ruby didn't work at all in the terminal (that is, it said: ruby:command not found.
Then I followed this thread RVM ruby installation issue and it worked. However, after I closed that terminal and opened a new one, it didn't work anymore.
Do I have to change something in the autostarts? Can someone please help me!!
Check if your ~/.profile file contains:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
and your .bash_profile file contains:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
if it have it and still don't work add this line to your ~/.bash_profile
source ~/.profile
I'm assuming you are using bash as your shell. You may want to check it in your user preferences (depend on your distro).
I assume the installation worked, what did not worked is you missed to use the installed ruby:
rvm use ruby-2.1.0
in your case it would print you a warning about not using login-shell - follow the instructions, they ae there to help you

OSX Lion New bash session rvm default ruby not used

I use OSX Lion. I have installed RVM and have put this line in my .bash_profile file.
[[ -s "/Users/Anand/.rvm/scripts/rvm" ]] && source "/Users/Anand/.rvm/scripts/rvm" # This loads RVM into a shell session.
I installed ruby-1.9.2-p290 and set it as default rvm ruby with this command:
rvm use --default ruby-1.9.2-p290
And when I checked ruby-v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
The problem is, every time I open a new terminal window or a tab, the default ruby is not getting set. The system ruby is instead getting used. ruby -v gives this:
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.3.2]
This also happens with reading .rvmrc file in a ruby project. When I'm inside a project and when a new tab gets opened, it gets me into the project directory but is not setting ruby according to .rvmrc in that project. What should I do to fix this?
I got the problem. It was with $PATH. I have to put rvm related line in the .bash_profile as the last line.
Old .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
source $HOME/Dropbox/dotfiles/bashrc
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
export PATH=/Library/PostgreSQL/9.0/bin:$PATH
New .bash_profile
source $HOME/Dropbox/dotfiles/bashrc
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
export PATH=/Library/PostgreSQL/9.0/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
And it worked. New windows and new tabs open up correctly with the default ruby i.e, ruby 1.9.2
I just fixed this very same issue. Turns out it was a path issue.
try this
➜ ~ which ruby
if you are getting /usr/bin/ruby, the path to your original ruby installation is overshadowing the default install in your RVM installation.
I added the path to RVM before the path (see below) to /usr/bin/ruby and it works as expected.
I use zsh as my shell, so I had to add this manually to my .zshrc
export PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting<br />
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
if you use bash
Your .bashrc probably looks like this
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
change it to this:
PATH=$HOME/.rvm/bin:$PATH # Add RVM to PATH for scripting
and make sure you .bash_profile has this:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
and you should be good to go.
Of course this means that your shell is going to look in your RVM directory first when looking for any command, but thats never caused any issues for me.
Question #1:
The command as listed is, you had switched '--default' and 'use'.
rvm --default use ruby-1.9.2-p290
Check if default is actually set:
$ rvm list default
Default Ruby (for new shells)
ruby-1.9.2-p290 [ x86_64 ]
Some other troubleshooting tips in case that doesn't work. Are you sure your bash profile file is being loaded? Try just having 'source "/Users/Anand/.rvm/scripts/rvm' instead of the check, maybe something is wrong with the path? Username does that begin with capital letter?
Question #2: You must cd into the directory with the .rvmrc file explicitly for the magic to happen. I suppose starting a console in a certain location doesn't trigger rvm. I run into this when using pushd and popd to switch between folders.
Try this first if rvm --default use doesn't work:
sudo rvm alias create default 1.9.2

How to use "RVM --default" on MacOSX

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 set up my .bash_profile as described in the documentation:
[[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm"
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 ~ $
I'm using 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.
Check all the files that load when you open a shell:
/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.
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.
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)
I had the same problem.
Moving:
[[ -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.
Run the command:
rvm use --default 1.9.2?
This worked for me on openSUSE, I don't know about Snow Leopard though.
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.
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.
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.
It happened to me, and I couldn't figure out why rvm doesn't use my default.
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.
After I added myself to it I can set --default.
My issue was resolved by changing
PATH=/usr/local/bin
to
PATH=$PATH:/usr/local/bin
in my .zshrc file.
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.
See "Sometimes, CD to a dir with .rvmrc doesn't set the Ruby version or gemset" for more information.
Try this to set default Ruby for a new shell:
sudo rvm alias create default 1.9.2
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.
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)
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.
What does type rvm | head -1 print out?
In my .bash_profile on the latest MacOS X I had to put:
# Ruby Version Manager
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
I also created a gemset and set this as default:
rvm reload
rvm install 1.9.2
rvm --create use 1.9.2#default
rvm --default use 1.9.2#default
You need to put the path to RVM in front of your PATH:
$ export PATH=/path/to/rvm-dir:$PATH
For some reason I had in my $HOME/bin directory ruby, gem, rake, ... file stubs. 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

RVM is not working in ZSH

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.
Do you have this line in your ~/.zshrc?
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
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 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
I got it working on Manjaro Linux (zsh) by adding source /usr/share/rvm/scripts/rvm to $HOME/.zshrc

Resources