4

I am new to RoR and I tried to follow the Ruby on Rails Tutorial from Micheal Hartl. Before starting the tutorial I already set up everything earlier and updated the Rails version to 4.1.1 and everything worked well until the point in the tutorial where I needed to have max 4.0.5 version of Rails in order to proceed with the example. In order to do so I tried several things. First I run:

gem uninstall rails

after which I received the message that it was uninstalled but when running rails -v I still had 4.1.1. Then,following one answer on stackoverflow, to uninstall railties, I did:

gem uninstall railties 4.1.1

after which when running: rails -v I got a message that version 3.2.18 was running which was the one I installed as part of the railsinstaller. Unfortunately, after creating a new app it stopped on the bundle install and didn't continue, for several times. Then I tried to remove all the gems in order to install everything from scratch. I did it with:

ruby -e "gem list.split(/$/).each { |line| puts gem uninstall -Iax #{line.split(' ')[0]} unless line.strip.empty? }"

which I also found here. It did remove the gems, after which I uninstalled Ruby. Then I installed everything again with the railsinstaller which has Rails version 3.2.18. When it finished and when I opened the cmd, in the Rails Environment Configuration under Rails version I could see again version 4.1.1. When i ran:

gem uninstall rails

it uninstalled the 3.2.18 version, the correct one. I installed everything again, hoping that the correct version is installed and that showing the 4.1.1 is a minor bug, but the bundler install still didn't work normally when creating a new app. Right now, after several tries, I tried to leave it as is, not to uninstall anything but to try to install the 4.0.5 version besides. First it installed railties and rails 4.1.1 and then I got an error: could not find a valid gem '4.0.5'.

I checked for several questions and answers, trying to set it up the whole day but it didn't work out. I tried to write details so you can understand better since there were similar questions but not targeting the exact same problem I have. Whatever I did I finished up with many gems with version 4.1.1 still being in the folders. I hope somebody will know what to do and how to remove the previous version forevr. Thanks in advance!

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
nera
  • 41
  • 1
  • 4
  • Are you actually sure that the tutorial does not work in 4.1.1? Might be an easy fix, or it might not be broken at all. But authors prefer to lock in a version of a software of avoid any problems that will some times arise. But there is a change that the tutorial will still work. – Mohamad May 19 '14 at 22:54
  • Did you check this one. http://stackoverflow.com/questions/6148308/set-rails-version-as-default – Tony Hopkinson May 19 '14 at 22:55
  • try to use the latest version of rails but if you can't. run `sudo gem uninstall rails -v 4.1.1`. if you want only the latest versions of the gems run gem cleanup – Sam May 19 '14 at 22:56
  • @Mohamad Chapter 3, part about secret tokens, the author said to uninstall if not having the proper file. – nera May 19 '14 at 23:16
  • @TonyHopkins I am on Windows so couldn't use RVM and pik didn't really work well when I tried. Will also have the cleanup in mind, thank u guys! – nera May 19 '14 at 23:19
  • I changed the Gemfile where I put 4.0.5 version after gem 'rails' and ran bundle update. It did work in the way of showing me the right version after: rails -v. But running the server didn't work afterwards. After I changed some other gems in the Gemfile and ran: bundle install, I had again the 4.1.1 version. – nera May 19 '14 at 23:37

2 Answers2

2

First find the rails gem directory.

There are many ways to do it, such as looking in your GEM_HOME and GEM_PATH

echo $GEM_HOME
echo $GEM_PATH

Here's a brute-force way:

find / -type d -name rails-4.1.1 

This may find multiple directories, such as the system's gem directory, cache, docs, bundler directory, ruby versioning directories for RVM or chruby, etc.

If you're the only user of the system, then remove all of these.

Immediately verify that 4.1.1 is gone:

# Show the executable, if any
which rails  

# Show the version, which should not say 4.1.1
rails --version

# If you're within a bundle directory
bundle exec rails --version

Do NOT bundle yet.

Edit your Gemfile, which may also be asking for Rails 4.1.1, and set the exact Rails version that you want:

gem 'rails', '= 4.0.5'

Now bundle:

bundle update

Verify that rails 4.1.1 is not in your Gemfile nor lock:

grep 4.1.1 Gemfile Gemfile.lock
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • It's not possible that it didn't work. ;) You must have run some command after you cleared out Rails 4.1.1. I'm adding more info now, and you're welcome to IM me on Google Chat if you want more help. – joelparkerhenderson May 20 '14 at 00:33
0

If you're using bundler (which is highly recommended), you should be able to use different versions of gems for different applications

--

Have you tried this:

In your Gemfile, make sure you have the correct version of Rails referenced -
gem 'rails', '3.2.0'

In your app directory - bundle install

--

This will use bundler to install the respective gems for your app, which can change as required

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147