Rails 3 is out, but version 2 is still widespread.
I have > 1 computers but I prefer to develop on one.
Inevitably the question arises: how can I develop in rails 2 and 3 on 1 machine?
Ruby Version Manager (RVM) becomes your friend
RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments from interpreters to sets of gems.
So not only is it convenient for rails 2 vs 3, but any new update that comes out can easily be tested this way.
Most of the following procedure comes from Michael Hartl's Learn Rails by Example that now covers rails 3 and is an excellent tutorial!
Quick procedure how to set it up and use it:
1. install RVM:
∴ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
.. and put this in your profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
2. install the Ruby instances you want:
$ rvm update --head $ rvm reload $ rvm install 1.8.7 $ rvm install 1.9.2
3. define two gemsets, basically self-contained workspaces between which you can toggle
$ rvm --create [email protected] $ rvm --create use [email protected]
4. make sure you have gem (Ruby's package manager) installed. It should come with RVM already.
I had some strange issues when installing gems. I think I used somehow the global gem's binary, so you might want to put the RVM's gem binary earlier in your PATH (adding ~/.rvm/rubies/ruby-1.9.2-p0/bin/gem to $PATH in for example .bashrc)
5. now you can easy toggle between the two environments
$ rvm 1.9.2 // toggle to rails 3 environment
$ gem list
$ rvm 1.8.7 // toggle to rails 2 environment
$ gem list
You can even run both versions at the same time if you specify a different port
$ ruby script/server
=> Booting WEBrick => Rails 2.3.8 application starting on http://0.0.0.0:3000
$ script/rails server -p 3001
=> Booting WEBrick => Rails 3.0.0 application starting in development on http://0.0.0.0:3001
Rails 2/ 3 happily running on the same host
OK, this Wednesday a new edition of my Web spotlights ... Apture, itunes ping and more stuff ..