Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Ruby Version Manager: Easily Use Multiple Ruby Versions At Once

By Peter Cooper / August 26, 2009

multiple-rubys.pngRuby Version Manager GitHub repo (a.k.a. RVM) makes it ridiculously easy to install and switch between multiple Ruby versions on OS X and Linux. Over the last 24 hours, I've been playing with RVM and talking to creator Wayne E. Seguin and have been blown away with how cool (and simple) it is - you will definitely want to check this one out.

RVM's most compelling feature is that it caters for six different distributions out of the box (MRI 1.8.6, MRI 1.8.7, 1.9.1, 1.9.2, Ruby Enterprise Edition 1.8.6, JRuby 1.3.1) and it'll install them the first time you need to use them. RVM doesn't mess up your current Ruby install - the RVM installed implementations are only activated manually by you and you can switch back to the "default" with one line.

It's possible to install different patch levels if you like too and Wayne has put together a list of examples to show you the various things RVM can do from the command line (including gem management).

Using Ruby Version Manager

I find shell sessions demonstrate how things work better than narrated instructions, so.. enjoy:

Installation

# gem install rvm
# rvm-install
 [Follow the prompts.. you can let it edit your ~/.profile or you can do it manually]

Using a different Ruby

# rvm use 1.9.2

  <i> Installing Ruby from source to: /Users/peter/.rvm/ruby-1.9.2-preview1
  <i>   Extracting ruby-1.9.2-preview1...
  <i>   Configuring ruby-1.9.2-preview1 using '--enable-shared', this may take a while depending on your cpu(s)...
  <i>   Compiling ruby-1.9.2-preview1, this may take a while, depending on your cpu(s)...
  <i>   Installing ruby-1.9.2-preview1
  <i>   Installing rubygems dedicated to ruby-1.9.2-preview1...
  <i> Installation of ruby-1.9.2-preview1 complete.
  <i> Installing rake

# ruby -v
  ruby 1.9.2dev (2009-07-18 trunk 24186) [i386-darwin9.8.0]

# gem list

  *** LOCAL GEMS ***

  hoe (1.11.0)
  libxml-ruby (1.1.2)
  minitest (1.4.2)
  rake (0.8.4)
  rdoc (2.2.2)
  rubyforge (1.0.3)

Note that instead of 1.9.2, you could use “ree”, “1.9.1”, “jruby” and more..

Returning to your default Ruby

# rvm use default

  <i> Switching to default   ...

# ruby -v
  ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]

RVM is still in its early days so don't try this on your production boxes just yet - unless you're brave! (Note: Two months have passed since RVM's initial release and it is now considered production ready.) You can catch up with the creator, Wayne Seguin, on irc.freenode.net in #rvm if you'd like to discuss the project further or, perhaps contribution installation scripts of your own to be added to the project.

A massive thanks to Jamie Van Dyke for giving me the lead on this useful tool.

Comments

  1. Christian says:

    Looks very promising! Unfortunately `rvm use 1.9.2` (and other versions) doesn't do anything: no output, no visible consequences. Same for `rvm usage`. I'm on Ubuntu 9.04.

  2. Justin Blake says:

    This is handy dandy. I finally have a super easy way to play with 1.9

  3. Peter Cooper says:

    Christian: I've been hanging out in irc.freenode.net #rvm for a while and a few little bugs here and there have come out of the woodwork but Wayne is working on them really quick. If you're at all able to drop in, we/he might be able to help.

    Also try using --debug as a switch at the end to see what commands are being run. It might give a clue. Feel free to post stuff here.

  4. Peter Cooper says:

    "wayneeseguin: holy crapintots.... 12 different people messaging me"

    Haha.

  5. Stephan says:

    Nifty!

  6. Danny Tatom says:

    I was kind of eerie to use these kind of things for a while, as I didn't want my system all cluttered up, but RVM is indeed pretty slick. Much thanks to Wayne for this. :)

  7. Christian says:

    Peter: No matter how I run the command (including with --debug) I get no response and no effects

  8. Jerod Santo says:

    This looks really cool, can't wait to give it a try!

    I wonder if Wayne took any inspiration from Rip, as it seems very similar in design

  9. Peter Cooper says:

    I think I have an Ubuntu 9.04 VM. I'll come on and have a go :)

  10. Peter Cooper says:

    Just done some work with Ubuntu. If you're using the Ubuntu packaged version of RubyGems, RVM does not work. BUT.. the Ubuntu packaged version of RubyGems is commonly acknowledged as a steaming pile of crap. I installed RubyGems manually (on top of packaged Ruby) and RVM then works great.

    If anyone wants instructions on installing RubyGems manually on Ubuntu (they work for 9.04 too), see http://www.rubyinside.com/how-to-install-a-ruby-18-stack-on-ubuntu-810-from-scratch-1566.html

  11. Wayne E. Seguin says:

    Christian,

    Please hop in #rvm on irc.freenode.net so that I can help you work through your issues in real time.

    Jerod,

    No I have not yet used / evaluated rip. I built rvm using my own ideas and then *lots* of feedback from the community.

    ~Wayne

  12. Peter Cooper says:

    Had an issue with REE on a stock Ubuntu 9.04. Turns out REE's installer was missing some things it wanted.. I had to install "libreadline5-dev" and "libssl-dev" packages. Now all works.

    The error was:

    Installing ruby-enterprise-1.8.6-20090610, this may take a while, depending on your cpu(s)...
    chmod: cannot access `/home/notroot/.rvm/ruby-enterprise-1.8.6-20090610/bin/*': No such file or directory

  13. Peter Cooper says:

    I identified why you get bizarre formatting in Snow Leopard. I suspect it will be fixed in the next gem release.. :)

  14. Chris Herring says:

    Does changing my ruby with this affect my textmate ruby? Can I switch to 1.9 and test my application against straight from there?

  15. Luis Lavena says:

    For anyone interested in something similar for Windows, there is Pik:

    http://github.com/vertiginous/pik/tree/master

    The good part is that no compilation is involved.

  16. Peter Cooper says:

    Chris: I just spent an hour looking into this, lol. TextMate is a pain in the ass in this regard. Basically it didn't respect the PATH switches RVM does at all and the TM stance seems to be you need to manually set the PATH in the preferences which is lame IMHO.

    The fix to make it all "just work":

    /Applications/TextMate.app/Contents/SharedSupport/Support/lib/tm/process.rb
    Line 125 becomes: exec("bash -lc '" + cmd.compact.join(" ") + "'")

    /Applications/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/RubyMate/run_script.rb
    Add a line before line 37 with: ENV['TM_RUBY'] = nil if ENV['TM_RUBY'] == '/usr/bin/ruby'

    The latter line is to override a bizarre TextMate default that people were complaining about way back in 2006... :P

  17. Peter Cooper says:

    Yes, I know I should probably do this as a proper patch ;-)

  18. Victor says:

    When would I need to use such a tool? I never needed to switch between different Ruby versions

  19. Chris Herring says:

    Looks sweet. Something I will have to look into after I install Snow Leopard tomorrow :)

  20. Christian says:

    Wayne, Peter: Thanks for helping out! Unable to get on irc right now.

    I'm off course using a properly installed RubyGems :) I also tried to update from 1.3.1 to 1.3.5 with no luck. Reinstalled rvm just to make sure, but still, no matter what I do, the rvm command has no output. Any other way I can debug this?

  21. Alexei says:

    Man, that is so cool, I have been recently trying to find a way of trying 1.9 and being able to switch back and forth. More people will give 1.9 a no-pain try and I think the faster we switch to 1.9 the better. Great job!

  22. type says:

    @Christian:
    me too.
    I use Ubutnu8.0.4

  23. nutjang says:

    So cool. I 've some problem with ruby version for a long time. thanks.

  24. James Schorr says:

    This works wonderfully! I set up an alias as well in my .bash_profile file, which really helps as I develop a lot of Rails apps:

    alias 19='rvm use ruby -v 1.9.1'
    alias 18='rvm use default'

    You can then either type in source .bash_profile or open a new Terminal window. Then, just type in 18 to use ruby 1.8.x, or 19 to use ruby 1.9.x.

  25. Wayne E. Seguin says:

    Christian,

    Please try Release 0.0.24:

    uninstall previous release gem, rm -rf ~/.rvm/ ; rvm-install ; open new terminal and give it a go.

  26. aunt darlene says:

    WAY TO GO NEPHEW!!!!!

  27. Alif Rachmawadi says:

    I am trying out rvm today and impress about it. Great concept.

  28. Devin says:

    I was able to install rvm with minor issues that involved my .profile/.bash_profile/.bashrc on Linux and OSX 10.5 respectively. If you choose to automatically add the rvm source line to your bash profile in `rvm-install`, it will add it to .bash_profile. On OSX, .bash_profile trumps your .profile, so remove .bash_profile and add the line .profile instead. On both Linux && OSX it is a good idea to add the rvm source line to the end of your profile, after any `export PATH` lines you might have.

    Wayne was an animal in #rvm. I came in at like 5pm and Wayne was STILL actively coding, fixing, taking suggestions, and helping users get rvm working at 11:00pm. The guy is an animal! And, I should add, an incredibly nice guy.

    Thanks so much Wayne. rvm is a fantastic edition that might actually get developers to start updating their gems to 1.9. :)

  29. Christian says:

    Wayne: Still no luck :( I'll my ass on irc this weekend, maybe I can help debug it.

  30. Wayne E. Seguin says:

    Christian,

    I should be around on and off this weekend. Leave a message and as I have time I'll help out.

    Also, more importantly I am almost done paying my technical debt with early implementation details in rvm and will be releasing 0.0.25 soon. It will be quite solid so I hope it fixes your issues. Please also keep an eye on the faq/notes page: http://rvm.beginrescueend.com/faq/ as perhaps someone will come across your particular issue.

    Thanks!

    ~Wayne

  31. Devin says:

    Christian, I had the same issue as you on OSX. After speaking with wayne for a little bit I found that explicitly sourcing the rvm script (source ~/.rvm/bin/rvm) in my .profile fixed the issue completely. Best of luck,

    $ Devin

  32. Christian says:

    Devin (and Wayne): sourcing the script explicitly solved the problems. Thanks alot, this gem is truly awesome!

  33. Greg says:

    Nice gem! It'll make life a lot nicer when porting between versions or testing for suspected version incompatibility.

    On OSX 10.5 I ran into a couple problems getting the Postgres drivers installed for ActiveRecord, Datamapper and DBI (ruby-pg, pg, do_postgres) . I finally figured out it was partly due to the voodoo involved in finding pg_config. I set PATH to include /usr/local/pgsql/bin/pg_config, which is where mine hides, and that took care of the problems.

    I'm back to hitting my databases and now testing with 1.9.1 to upgrade some code. Thanks!

  34. Joe Lapp says:

    On OSX 10.5 I get the following error attempting to run rvm-install:

    sh: bash -l -c 'cd /Library/Ruby/Gems/1.8/gems/rvm-0.0.27 && ./scripts/rvm-install && source ~/.rvm/scripts/rvm': No such file or directory

    I have a feeling this is related to Christian's problem, but adding "source ~/.rvm/bin/rvm" to my .profile didn't help. I have no clue what that does, so I don't know if I understood the suggested solution.

    ".../rvm-0.0.27/scripts/rvm-install" does exist, but "~/.rvm" does not. I ran "sudo gem install rvm" and "sudo rvm-install" (failing with the above error) from my home directory. Thanks!

  35. Joe Lapp says:

    I couldn't resolve my problem and found a way to build 1.9.1 directly. Don't think I need 1.8.x for new development.

  36. Wayne E. Seguin says:

    Joe,

    Please hop in #rvm on irc and I will help you with any issues.

    I am usually in there 09:00-17:00, 21:00-~00:00 EST

    Thanks,

    ~Wayne

Other Posts to Enjoy

Twitter Mentions