Confession: I’m still using Ruby version 1.8.7, from the Ubuntu 10.10 repository. Why? I have a lot of working code, I don’t know how well it works using Ruby 1.9 and I’m worried that migration will break things and make me miserable.
Various people have pointed me to RVM – Ruby Version Manager. As the name suggests, it allows you to manage multiple Ruby versions on your machine. Today, I needed to test an application written for Ruby 1.9.2, so I used RVM for the first time. Here are the absolute basics, for anyone who just wants to test some code using Ruby 1.9, without messing up their existing system:
# install rvm bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) # add it to your .bashrc echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc # add tab completion to your .bashrc echo '[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion' >> ~/.bashrc # source the script; check installation source ~/.rvm/scripts/rvm rvm -v # returns (e.g.) rvm 1.2.8 by Wayne E. Seguin (firstname.lastname@example.org) [http://rvm.beginrescueend.com/] # install ruby 1.9.2 rvm install 1.9.2 # use ruby 1.9.2 rvm use 1.9.2 ruby -v # returns (e.g.) ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] # do stuff as normal (install gems etc.) # when you're done, switch back to system ruby rvm system ruby -v # returns (e.g.) ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
That’s it. The key thing is that RVM sets up Ruby in $HOME/.rvm so for example, when using version 1.9.2 under RVM, gem install GEMNAME will install to $HOME/.rvm/gems/ruby-1.9.2-p180/gems/. Your system files are untouched.