I can not update the Ruby on Rails version

0

I want to update the ruby on rails version. I'm using ubuntu and when I run:

rails -v
Rails 4.2.7.1

It tells me that I have version 4.2.7.1 installed.

To update the command I want to use:

sudo gem install rails -v 5.1.4
Successfully installed rails-5.1.4
Parsing documentation for rails-5.1.4
Done installing documentation for rails after 0 seconds
1 gem installed

But when I rerun the rails -v command to verify the version, it keeps showing me the previous one

rails -v
Rails 4.2.7.1

Someone knows how I can fix it, the same thing happens to me in Mac Os X

    
asked by Sanx 12.09.2017 в 21:17
source

2 answers

0

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 )
answered by 12.09.2017 в 23:17
0

When installing rails, do not use the sudo command, otherwise, some of the functions will be available only to the sudo user and not for a normal user, or you will start to see random errors or whose messages are not clear.

If you just started with rails, I recommend that you try to uninstall everything and start over, anything that does not require apt-get throw without sudo.

    
answered by 04.04.2018 в 09:37