Ruby on Rails

Using a specific rails version when you generate a new rails app with rails new command

Most of the times you want to develop using the edge version of rails. However, many times you need to generate an application with a specific version of rails. This minipost will guide you through on how to do that.

Before attempting to generate a fresh rails app with the rails new command you should check for versions of rails you have already installed on your system. This can be done with the following command:

  $ gem list rails --local

The above will output all the gems that contain the word rails and the rails gem itself. So look for something like the following:

*** LOCAL GEMS ***

rails (4.2.7)

Inside the parenthesis you can find all the versions of rails you have installed locally. If you do not find the desired version you should install it:

  $ gem install rails -v '' -V --no-ri --no-rdoc

Having finished the fresh rails installation, you should check again with the gem list command if it is now present inside the parentheses. Now, go to the directory you wish to generate your new app and run:

  rails _4.2.7.1_ new appname

Where appname the name of your rails application.

Enter the directory of your newly generated application and check for the rails version:

$ cd appname
appname$ rails -v

You should also check your Gemfile for the specific rails gem version. So, being inside the newly generated application directory you should cat the Gemfile and on the first lines you should be able to see the rails gem with its version:

$ cd appname
appname$ cat Gemfile

the last one, will output your Gemfile and in the first lines you should be able to see the rails gem version:

source ''

ruby '2.3.1'
gem 'rails', ''

The scaffold of the rails application is now ready for you to start developing your ideas and bring to life wonderful things on a specific version of rails. Good luck!

Buy Me A Coffee

Read also the following