We build Web & Mobile Applications.

< All Articles

Specify a version with the 'rails' generator

The first thing most people do when starting a new Rails project is to use the rails generator to create the basic application structure.

By default you’ll be using the most recent version of Rails that’s installed on your system, for example:

rails -v
=> Rails 2.3.2

A few weeks back we were training a bunch of eager new Rails developers and one of them asked if they could specify the version of Rails to use if they had multiple versions installed.

The simple (if a little weird and not particularly well documented) answer is that you can pass the version number as the first parameter, surrounded by underscores like this:

rails _1.2.3_ -v
=> Rails 1.2.3
rails _2.1.0_ -v
=> Rails 2.1.0

If you specify a version that you don’t have installed you’ll get a gem activation error, like this:

/Library/Ruby/Site/1.8/rubygems.rb:636:in `report_activate_error': RubyGem version error: rails(1.2.6 not = 2.5.0) (Gem::LoadError)
    from /Library/Ruby/Site/1.8/rubygems.rb:141:in `activate'
    from /Library/Ruby/Site/1.8/rubygems.rb:49:in `gem'
    from /usr/bin/rails:18
Updated on 07 February 2019
First published by Chris Anderton on 02 April 2009
© Chris Anderton 2019
"Specify a version with the 'rails' generator" by Chris Anderton at TheWebFellas is licensed under a Creative Commons Attribution 4.0 International License.