RVM doesn't switch Rubies - ruby

I'm running Ruby 1.9.1p243 on CentOS, and I decided to install rvm to handle upgrading to 1.9.2 or downgrading to 1.8.7 (whichever turns out to work better for rails3).
I followed the instructions here: http://rvm.beginrescueend.com/rvm/install/ and everything installed correctly. I was able to compile and install Ruby 1.8.7, 1.9.1, and 1.9.2.
However, if I try to actually switch to one of the rvm installed Rubies, with rvm use 1.8.7, for example, nothing works. My system still uses the Ruby I have installed in /usr/local/bin/ruby.
An example of the output I get:
$ rvm use 1.8.7
$ ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]
$ which ruby
/usr/local/bin/ruby
$ rvm use 1.9.2
$ ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]
$ which ruby
/usr/local/bin/ruby
I have no idea why this is happening, and I can't seem to find anything online about the issue either. Any help would be appreciated.

Just came across the same problem.
Instead of appending the following script to ~/.bash_profile, append it to ~/.bashrc:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
And then restart the terminal.

Typically rvm support is easiest via IRC (#rvm on freenode) - in this particular case, what does running "type rvm | head -n1" show? it should show "rvm is a function". If not, that means the line to source rvm isn't being run correctly and hence switching doesn't work. Typically this means you either have a return in your ~/.bashrc or you missed adding the line to source rvm.

Your install it as root account.
Try this in shell:
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"
before rvm switch operation. I add this line in my profile file and now all is ok.

Can be a problem of Terminal and
you should try to close your Terminal's window
and to open new one. :)
Try again to see if it has changed...

I've been struggling with setting default rvm ruby to no avail, until I've tried this:
sudo bash -l -c 'rvm alias create default ruby-1.9.3-p392'
"sudo" is for writing into /usr/local/rvm/config/alias (in my example it would contain "default=ruby-1.9.3-p392")
"bash -l" is to make sure it runs all the scripts (/etc/profile, /etc/bash.bashrc, etc..) of login shell

Related

Ruby 1.8.7 upgrade to ruby 1.9.2

I am going through this tutorial, but I already had Ruby 1.8.7 installed. I need to have 1.9.2/1.9.3 version.
I started to use RVM.
$ rvm list rubies
rvm rubies
ruby-1.8.7-p358 [ x86_64 ]
ruby-1.9.2-p318 [ x86_64 ]
=* ruby-1.9.2-p320 [ x86_64 ]
ruby-1.9.3-p194 [ x86_64 ]
# => - current
# =* - current && default
# * - default
but if I run ruby -v it returns still 1.8.7.
$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
other return values:
$ whereis ruby
ruby: /usr/bin/ruby /usr/bin/ruby1.8 /usr/lib/ruby /usr/share/man/man1/ruby.1.gz
$ which rails
/usr/local/bin/rails
$ which ruby
/usr/bin/ruby
When you're typing ruby you're still hitting the system ruby, not the rvm ruby.
Did you follow all the directions here: https://rvm.io//rvm/install/ ?
It looks like you're running Linux -- did you see this section in the rvm install docs?
If you open a new shell and running:
$ type rvm | head -1
does not show "rvm is a function", RVM isn't being sourced correctly.
Ensure that RVM is sourced after any path settings as RVM and manipulates the path. If you don't do this, RVM may not work as expected.
If you are using GNOME on Red Hat, CentOS or Fedora, ensure that the Run command as login shell option is checked under the Title and Command tab in Profile Preferences. After changing this setting, you may need to exit your console session and start a new one before the changes take affect.
Also, rvm adds some lines to your .bashrc file to load itself into memory whenever you open a console session. It looks like this may be your issue.
In my .bashrc, for example, rvm inserted the following:
export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql84/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Is there something similar in yours? Also, if you're using z-shell you may need to take some extra steps that are outlined in the install docs.
Try
$ rvm use ruby-1.9.2-p320
then
$ ruby -v
what does this return?
This should change your ruby version to ruby-1.9.2-p320 in the current console and if you want it on every new opened terminal you may use --default option
try
$ rvm --default use ruby-1.9.2-p320
then
$ruby -v
should return ruby-1.9.2-p320 version in the current and in every new window terminal opened.
Any time you want to return to your system ruby installation
use
$ rvm use system

Why won't my rvm allow me to switch to an alternative Ruby?

Ubuntu already has Ruby 1.8.7 installed. Then I installed rvm and used it to install Ruby 1.9.2, which is the version I want to use. However, ruby -v always returns 1.8.7.
How do I get rvm to use Ruby 1.9.2?
bxu#vm-bxu:~$ rvm use 1.9.2
Using /usr/share/ruby-rvm/gems/ruby-1.9.2-p320
bxu#vm-bxu:~$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
The Problem
RVM does its own installation magic, but in Ubuntu's case it doesn't always install to the right Bash startup file. You probably don't actually have RVM running properly; even though it's sort of installed.
The Fix
You need to make sure the following two lines are at the BOTTOM of your ~/.bashrc file.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
export PATH=$PATH:$HOME/.rvm/bin
Then restart your terminal emulator or log back in. Note that sourcing ~/.bashrc has been known not to work in some cases, so this step will save your sanity.
RVM should now be working properly. The last step is to set your default Ruby.
rvm --default use 1.9.2
Important Edit
As I've just been reminded, RVM breaks Ubuntu login shells by installing ~/.bash_login, which overrides your Ubuntu ~/.profile in login shells. Move the code over to your ~/.bashrc if you haven't already done so, then remove or rename ~/.bash_login.
From the terminal:
rvm use 1.9.2
on Ubuntu you need to enable login shell in your terminal emulator, we have a quite good documentation for this at rvm site:
https://rvm.io/integration/gnome-terminal/

rvm does not set ruby version

i am new to linux. i have kubuntu 11.10 , i have installed ruby 1.9.2 and only after this i have installed rvm. after this i made
rvm install 1.9.2
and
rvm install 1.8.7
and when i use
rvm use 1.8.7
ruby -v
it writes
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
i tryed to use another versions but it writes same anyway, so i think that rvm dont have priority to choose ruby version. how to solve this problem? It's cause i have installed ruby and only after this i have installed rvm?
looking at the output of your rvm list, you have two rubies installed, none of them default.
Looks like you just missed the step to make 1.9.2 the default.
And it seems you didn't modify your .bash_profile file
See Step 3 on this page:
http://beginrescueend.com/rvm/install/
Your file ~/.bash_profile should contain this line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
(make sure to start a new shell, after modifying .bash_profile)
Then run this: (to set the default Ruby version)
rvm --default use 1.9.2
ruby -v
See also:
http://beginrescueend.com/rubies/default/
First you should establish if rvm is installed correctly, you can determine that by entering type rvm | head -1 in your terminal. If you get the response rvm is a function then rvm is installed correctly.
If it's an installation problem carefully go back over each step, if you still can't figure out what's wrong I highly recommend visiting the #rvm channel on freenode (irc). The creator and other knowledgeable rvmers are almost always available, friendly and willing to help you troubleshoot. If you end up using ruby extensively, you're going to start needing more of the functionality rvm offers (gemsets, etc.) and #rvm can be a great resource when you get tripped up.

Updating to Ruby 1.9.2 on Leopard 10.5.8 using RVM

There seems to be a lot documented on migrating to 1.9.2 via snow leopard but not a lot on Leopard specifically.
running Mac OS X Leopard 10.5.8
rvm 1.6.3
xcode 3.1.4
I had a hard time installing rvm to begin with- but used this fix and got rvm installed. I type:
$ rvmsudo rvm install ruby-1.9.2-head
Install of ruby-1.9.2-head - #complete
(I get a failure if I try install without a sudo command) To switch default versions:
$ rvmsudo rvm --default use ruby-1.9.2-head
Using /usr/local/rvm/gems/ruby-1.9.2-head
$ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin9]
When I set it as the default without a sudo command.
rvm --default use ruby-1.9.2-head
I get an error log that ends with:
cp: /usr/local/rvm/bin/rdoc: Permission denied
cp: /usr/local/rvm/bin/ri: Permission denied
cp: /usr/local/rvm/bin/ruby: Permission denied
cp: /usr/local/rvm/bin/testrb: Permission denied
Then I type
$ ruby -v
ruby 1.9.2p188 (2011-03-28 revision 31204) [i386-darwin9.8.0]
But when I close out terminal and reopen it is back to 1.8.7
Any ideas on how to get this ruby install to stick as my default?
Here is my bash profile
PS1="\u$ "
alias ll="ls -lahG"
export PATH="/usr/local/rvm/rubies/ruby-1.9.2-head/bin:/usr/local/bin:/usr/loca$
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loa$
##
# Your previous /Users/mikalfm/.bash_profile file was backed up as /Users/mikal$
##
# MacPorts Installer addition on 2011-04-23_at_21:38:56: adding an appropriate $
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# MacPorts Installer addition on 2011-04-23_at_21:38:56: adding an appropriate $
export MANPATH=/opt/local/share/man:$MANPATH
# Finished adapting your MANPATH environment variable for use with MacPorts.
UPDATE
Solved.
I went to the file location from 'which ruby' (the 1.8.7 version)
Backed up the file and deleted it.
Now ruby -v returns
ruby 1.9.2p188 (2011-03-28 revision 31204) [i386-darwin9.8.0]
See comment below about why this was a bad idea.
Update 2
Solved, Really Unless of course I did something dumb.
So after following the instructions from the thread- I cleared up all of the Sudo issues in the original question. I did it by uninstalling RVM using an implode command, removing the folder and reinstalling without using any sudo commands.
The following problem was I could force rvm to use 1.9.2 as a default for only one session at a time. I just fixed this by reading this stackthread force rails to use 1.9.2 in it someone proposed using the $ echo $PATH command. I did it and it looked fundamentally different than what I thought was in my bash profile.
It looked like
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/Users/mikalfm/.rvm/gems/ruby-1.9.2-p180/bin:/Users/mikalfm/.rvm/gems/ruby-1.9.2-p180#global/bin:/Users/mikalfm/.rvm/rubies/ruby-1.9.2-p180/bin:/Users/mikalfm/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin
Turns out, I thought a few lines in my .bash_profile were commented out by ## and weren't.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH and export MANPATH=/opt/local/share/man:$MANPATH. They directly contradict what I thought was my $PATH export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
I deleted those lines from my profile. I figure I can add them back in if and when there is a dependency and I need to use Mac Ports again. Again, some one let me know if this is the wrong approach, but it works for me now even when I start a new terminal.
Solved. I went to the file location from 'which ruby' (the 1.8.7 version) Backed up the file and deleted it. Now ruby -v returns ruby 1.9.2p188 (2011-03-28 revision 31204) [i386-darwin9.8.0]
NO NO NO!
The version of Ruby installed by Mac OS in /usr is owned by Apple and installed for their use. Applications installed by Apple use it, and you could have broken them.
If you run find /usr -name '*.rb' you'll find a number of files used by Apple, that are not part of the normal Ruby install.
It's not a problem of 10.5, I use it on my MB pro too. You need to learn to stop using sudo, when you do your not in scope of 'Mikal' anymore. I seldom have to use that anymore.
I'm not too familiar with rvmsudo. What happens when you do
rvm list
rvmsudo rvm list
?
My advice, uninstall rvm installed as root (with sudo), re-try and follow the guide at rvm.beginrescued.com
remove the PATH ruby1.9.2/bin from .bash_profile to avoid confusion. Let rvm handle it, and stay off sudo and rvmsudo (I've never used the latter).
rvm install 1.9.2
rvm use 1.9.2 --default
rvm list #see your rubies
should be sufficient. Hope it helps.
maybe you should just add:
rvm use 1.9.2
to your .bash_profile file :)

Mac snow leopard: ruby version kept coming back to 1.8.7

I installed ruby 1.9.2 and checked with ruby -v and it was fine (1.9.2) but after I restarted my computer after terminal somehow stopped responding, ruby switched back to 1.8.7. This has happened before and I ended up re-intalling.
Do you know what might have happened?
Thank you so much!
Cheers,
eFan
Try:
$ which ruby
And:
$ echo $PATH
I bet you installed ruby in /usr/local/ruby/bin/ruby but are running the one in /usr/bin/ruby.
Presumably you edited your PATH variable in that one Terminal session, but not for all future sessions. Assuming that you have a symlink from /usr/local/bin/ruby to the correct install, you need to modify your PATH to look in /usr/local/bin before /usr/bin.
Create or edit a file named .profile in your home directory with this line in it:
export PATH="/usr/local/bin:$PATH"
$ curl -L http://get.rvm.io | bash
$ rvm install 1.9.2
$ rvm use 1.9.2 --default

Resources