It’s quite easy to have multiple versions of rails installed as gems when working with ruby on rails. Quite frequently, you will be working on a project that uses an older version of rails than one on your machine, and all you have to do to get the correct version is:
gem install -v 1.2.3 rails --include-dependencies
Multiple versions of rails can exist independently on your machine without much of a problem. Since your individual rails projects store the version number they expect, and your projects don’t tend to depend on each other, you can have hundreds of different rails versions installed and never notice. Mostly.
If, however, you wish to start a NEW project, when you run
rails projectname
It will use the most recent version of rails. But what if, for some reason, you have rails 2.0.1 and rails 1.2.6 on your machine, and wish to generate a rails 1.2.6 application? This came up because I’m trying to teach a friend rails, and the book he has is for rails 1.2, meaning that if he uses 2.0 all of the scaffolding code (as well as other bits) from the book are incorrect. At the same time, the application he and I are working on together uses rails 2.0, so he needs both versions on his machine.
This solution works in linux (haven’t tried windows):
rails _1.2.6_ projectname
I didn’t see any documentation about this anywhere. In fact, I found it by cracking open the actual ‘rails’ script in /usr/bin and noticing that it did a regex match for a parameter that started and ended with underscores, then interpreted that as the version.
In any case, this allows you to happily generate a new rails app using an old version of rails. Nothing quite like discovering an undocumented feature by reading the source code.
Absolutely No Machete Juggling is a blog about software, programming, computers, and me. I'm a programmer working in Colorado, mostly with Java and Ruby. 
Thanks, Glad you are out there sharing info.
Thanks!! Its working..
Very helpful! Thanks!
The same command works in Windows as well.
Here is an example
rails _2.3.5_ project_name -d mysql
It specifies to create rails project with the rails 2.3.5 version and the database as mysql.
Works on mac – thanks.
Shouldn’t a ‘sudo’ be prefixed to it? it gives me warnings such as:
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren’t both writable.
WARNING: You don’t have /Users/myname/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
I don’t know much about Unix, Mac and command lines, but I assume this should be done?
I deleted that .gem directory it created with rm -r and then ran the command again with sudo. Now it didn’t give warnings.
Thanks for such a clear, short and to-the-point tutorial!
helpful while trying out rails 3. thanks!
Thanks again!
[...] somewhere. I google for “multiple versions of rails” and find a brief blog post about Using Multiple Versions Of Rails that gives me this useful piece of information: your individual rails projects store the version [...]
Thanks! This was just what I needed. (I’m developing a 2.3 app and learning from the same book)
Thanks for posting this. You’ve just saved me a ton of time and helped me with ensuring backwards compatibility of some code I’m modifying.
Thanks, answered my question.
Thanks, this helped me. FYI, I was juggling 2.0.2 and 2.1.1, and this advice still worked. Prior to finding this post, I did in fact open up the executable myself, however I failed to notice the _’s in the regexp.
-John