To verify the versions of Rails that you have installed on your system (for the Ruby version active at the moment), simply execute the following command:
$ gem list rails
This command will show you the gems that contain rails
in their name, only find the gem rails
which will show, in parentheses, all installed versions; For example, the result on my machine is this:
rails (5.1.3, 5.1.1, 5.1.0, 5.0.2, 5.0.1, 5.0.0.1, 5.0.0, 4.2.8, 4.2.6, 4.2.1)
So, if I run rails -v
in a directory where I have not installed / created an Rails application, I'll get the latest installed version; in my case this would be the result:
$ rails -v
Rails 5.1.3
However, if I run the command from a directory where an Rails application exists, then it will show me the version with which that application was created (ie the one that is specified in the Gemfile of the application); for example:
$ cd rails_4_app
$ rails -v
Rails 4.2.1
If you create a new application you must specify the version of Rails that you want to use, otherwise the application will be created with the latest version you have; for example:
$ rails _4.2.1_ new mi_app_con_rails_4
If you are looking to update the Rails version in an existing application , then you must update the Gemfile of the application, indicating the version of Rails you want to update (it is not necessary to have the gem installed on your machine):
# Gemfile
source 'http://rubygems.org'
rails gem 'rails', '5.1.4'
# otras gemas
And, once the Gemfile has been updated, it updates the installation of the new gem with bundler :
$ bundle install
IMPORTANT
Updating the Rails version in an existing application is not a trivial task and, if it is not done in an orderly fashion, it can be a real nightmare (depending on the complexity of the application). p>
Therefore, if you are going to update an application, I recommend (as a minimum) the following:
- Keep your test suite up to date
- Update one version at a time (for example, in your case I would do it in this order: 4.2.9 > 5.0.6 > 5.1 .4 )