Specifying rails version to use when creating a new application

I have two versions of rails (2.1.0 and 2.2.2) installed in my computer.

When I create a new application, is it possible to specify that I want to use the older (2.1.0) version?


I found here an undocumented option to create a new application using an older version of Rails.

rails _2.1.0_ new myapp 

Here is the command which I use normally:

rails _version_ new application_name

for example rails _2.1.0_ new my_app

Here is the list of all available rails versions so far:

http://rubygems.org/gems/rails/versions


I was having some trouble using rails _version_ new application_name (the resulting project was still generated for the newest version of Rails installed.)

After a bit of digging I found an article by Michael Trojanek with an alternative approach. This works by creating a folder with a Gemfile specifying the desired version of Rails and then using bundle exec rails... so that Bundler takes care of running the appropriate version of rails. e.g. to make a new Rails 4.2.9 projects the steps are:

mkdir myapp
cd myapp
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '4.2.9'" >> Gemfile
bundle install

bundle exec rails new . --force --skip-bundle
bundle update