Ruby Version Manager: Easily Use Multiple Ruby Versions At Once
Ruby 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.
August 26, 2009 at 7:31 pm
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.
August 26, 2009 at 7:50 pm
This is handy dandy. I finally have a super easy way to play with 1.9
August 26, 2009 at 7:54 pm
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.
August 26, 2009 at 7:58 pm
"wayneeseguin: holy crapintots.... 12 different people messaging me"
Haha.
August 26, 2009 at 8:11 pm
Nifty!
August 26, 2009 at 8:35 pm
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. :)
August 26, 2009 at 8:40 pm
Peter: No matter how I run the command (including with --debug) I get no response and no effects
August 26, 2009 at 9:40 pm
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
August 26, 2009 at 9:42 pm
I think I have an Ubuntu 9.04 VM. I'll come on and have a go :)
August 26, 2009 at 10:26 pm
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
August 26, 2009 at 10:56 pm
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
August 26, 2009 at 11:39 pm
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
August 26, 2009 at 11:50 pm
I identified why you get bizarre formatting in Snow Leopard. I suspect it will be fixed in the next gem release.. :)
August 27, 2009 at 12:05 am
Does changing my ruby with this affect my textmate ruby? Can I switch to 1.9 and test my application against straight from there?
August 27, 2009 at 12:20 am
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.
August 27, 2009 at 1:55 am
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
August 27, 2009 at 1:55 am
Yes, I know I should probably do this as a proper patch ;-)
August 27, 2009 at 3:58 am
When would I need to use such a tool? I never needed to switch between different Ruby versions
August 27, 2009 at 4:47 am
Looks sweet. Something I will have to look into after I install Snow Leopard tomorrow :)
August 27, 2009 at 5:42 am
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?
August 27, 2009 at 5:55 am
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!
August 27, 2009 at 8:16 am
@Christian:
me too.
I use Ubutnu8.0.4
August 27, 2009 at 8:54 am
So cool. I 've some problem with ruby version for a long time. thanks.
August 27, 2009 at 8:59 pm
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.
August 27, 2009 at 9:31 pm
Christian,
Please try Release 0.0.24:
uninstall previous release gem, rm -rf ~/.rvm/ ; rvm-install ; open new terminal and give it a go.
August 28, 2009 at 3:15 am
WAY TO GO NEPHEW!!!!!
August 28, 2009 at 3:52 am
I am trying out rvm today and impress about it. Great concept.
August 28, 2009 at 6:30 am
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. :)
August 28, 2009 at 7:43 am
Wayne: Still no luck :( I'll my ass on irc this weekend, maybe I can help debug it.
August 28, 2009 at 4:58 pm
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
August 28, 2009 at 7:23 pm
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
August 28, 2009 at 8:14 pm
Devin (and Wayne): sourcing the script explicitly solved the problems. Thanks alot, this gem is truly awesome!
August 29, 2009 at 2:51 am
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!
September 6, 2009 at 4:51 am
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!
September 8, 2009 at 4:16 am
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.
September 15, 2009 at 6:04 pm
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