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 (5.2.3)

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 '5.2.3' -V --no-document

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 _5.2.3_ 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
Rails 5.2.3

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 'https://rubygems.org'

ruby '2.7.2'
gem 'rails', '5.2.3'
[...]

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.

Buy Me A Coffee

Read also the following