Issue upgrading to Rails 5.1.4 - ruby-on-rails

I attempt to upgrade to Rails 5.1.4. Seems to update without an issue, however, a version check still shows 5.0.4. Any ideas?
Ruby Version:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Terminal Output:
$ rails -v
Rails 5.0.4
$ gem install rails --version=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
$ rails -v
Rails 5.0.4

Uninstall all versions of rails installed in your system by:
gem uninstall rails
It should prompt you with something like below
Select gem to uninstall:
1. rails-4.2.6
2. rails-5.1.4
3. All versions
Choose Option "All Versions" and uninstall all
Install the desired rails version:
gem install rails --version=5.1.4
rails -v
5.1.4
Update: Since you mentioned using bundle install, check if rails is specified with 5.1.4 in your Gemfile or not.

Sometimes, i met this problem, because you have two versions of rails in your railties. You can do this
gem uninstall railties
Select gem to uninstall:
1. railties-5.1.4
2. railties-5.0.4
3. All versions
Type 3 to remove all, then you can reinstall rails 5.1.4 again.

Either use
bin/rails -v
or
bundle exec rails -v
to select the version of rails specified in your Gemfile
Or do what I do and install https://direnv.net/ and add a .envrc file to the project. Then when you cd to that project, the path will be updated appropriately and rails -v will work as expected:
PATH_add "./bin"

Related

installing rails in rbenv with an old ruby

I'm working on a project in ruby 2.1.10. it should be using rails 4.0.13.
I'm using rbenv.
I've installed everything, I believe. I ran bundle install for the project. eventually I got it to run.
However, now I get:
turlingdrome$ rails
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
turlingdrome$ gem install rails -v 4.0.13
Successfully installed rails-4.0.13
Parsing documentation for rails-4.0.13
Done installing documentation for rails after 1 seconds
1 gem installed
turlingdrome$ which rails
/Users/brianp/.rbenv/shims/rails
turlingdrome$ rails -v
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
turlingdrome$ ruby -v
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin16.0]
in case it matters, I'm on a mac running 10.12.6
ETA from comment:
turlingdrome$ bundle exec rails -v
Rails 4.0.13
so, bundle exec lets me run rails. rbenv exec rails seems to work too.
So, the problem seems to be in the shim!
Rehash the shims:
rbenv rehash
Now you should be able to run only rails without bundle exec or rbenv exec.

rails -v keeps saying Rails 3.2.13 after installing 4.2.2

What gives?
I typed this in gem install rails -v 4.2.2
After that, I tried rails -v, and it keeps coming out Rails 3.2.13
Why is this?
My ruby version after ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]
You can manage gems with bundler (http://bundler.io/)
Put this on your Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem install bundler
and then
bundle install
bundle exec rails -v
If you still working without bundler, you can make
gem list
look at your rails version and then uninstall older versions
gem uninstall rails --version 3.2.13
and then
rails -v
I've encountered this before. And this is what I did.
Change version of rails
Just change the versions.
If you have multiple versions of Rails installed, you'll get conflicting information like this.
If you need to run a command with a specific version of Rails, you can specify the version as part of the command, eg.
rails _4.2.2_ -v
That will tell you you are using Rails 4.2.
Once you've created a new app by doing something like rails _4.2.2_ new app_name, then the Gemfile for that app will specify Rails 4.2.2 and you can drop the special prefix.

How to downgrade my rails version?

I am using rails version 4.2.0. How can I downgrade to version 3.2.19?
I tried the following:
I opened command prompt.
I typed gem uninstall rails
Some options came for rails version then I selected my current version and pressed entered.
Then typed gem install rails -v 3.2.19 for installing this version.
I went to my Site directory and typed rails new blog
When I opened the Gemfile of blog application I found again Rails version 4.2.0 is present there.
Do:
gem uninstall rails
gem uninstall railties
Followed by:
gem install rails -v 3.2.19
To check a rails version, directly do:
rails -v
Another workaround:
add following to your Gemfile:
gem 'rails', '3.2.19'
and then run:
bundle install
Or you dont have to downgrade. You can always create a new rails app with a specific version(if that version is already installed)
rails _3.2.19_ new myApp
That is not good approach to uninstall a global version of Rails. So just create a Rails app:
rails new app
then change Rails version in its Gemfile, and issue bundle install:
cd app
sed "s/'rails', '~> 4.2.0'/'rails', '~> 3.2.19'/" -i Gemfile
bundle install
Then, I believe, you should change all the dependent packages to older versions.

How to switch rails 4 to rails 3?

This is what I have done:
gem uninstall rails
gem uninstall railties
gem install rails 3.2
And terminal shows this code:
Done installing documentation for rails, railties after 1189 seconds
ERROR: Could not find a valid gem '3.2' (>= 0) in any repository
2 gems installed
weare138#mycomp:~$ rails -v
Rails 4.1.5
How to fix it?
You are missing the -v flag so rubygems is thinking that 3.2 is the name of a different gem and you are installing the current version (4.1.5). Instead try:
gem install rails -v 3.2.19
You should not need to remove up-to-date versions as you can specify the older rails version when starting a project with:
rails _3.2.19_ new myapp
If you are using RVM, create a new gemset
rvm gemset create <name>
Then you can switch to that gemset using
rvm use 1.9.3#<name> #assuming your ruby version is 1.9.3
That gives a clean gemset you can install Rails 3.2 to. Maintain multiple gemsets and switch between them

"Rails is not currently installed" Error

Hi i'm new to ruby on rails
I have 3 ruby version in my computer.
In a project i had to use rails 3.2.1 and ruby 1.9.2
So I switched using rvm use 1.9.2 in terminal. But after that my rails commands are not detected.
$ rails g model abc
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
Why is this happening? And how to solve this?
You may need to differentiate your gem set that contains that specific version of rails from the old ones.
rvm use 1.9.2#new_gem_set_of_yours --create --default
And then retry installing the 3.2.1 rails
gem install rails --version 3.2.1
Or specify the new rails version in your Gemfile and let Bundler take care of it
gem 'rails', '3.2.1'
and run bundle install.
Type in your terminal
gem install rails -v 3.2.1
if it does not work, first try
rvm install 1.9.3
then
rvm rubygems current
and repeat.

Resources