19

In Gemfile I made the following change:

-bash> git diff Gemfile
...
-gem 'rails', '4.0.4'
+gem 'rails', '4.0.5'

I then ran bundle and got a show-stopping message:

-bash> bundle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
You have requested:
  rails = 4.0.5

The bundle currently has rails locked at 4.0.4.
Try running `bundle update rails`

I then ran bundle update rails, as per the above message, and got the following (note that I am skipping lines without change).

-bash> bundle update rails
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Installing rake 10.3.2 (was 10.3.0)
Installing multi_json 1.10.1 (was 1.9.2)
Installing activesupport 4.0.5 (was 4.0.4)
Installing actionpack 4.0.5 (was 4.0.4)
Installing actionmailer 4.0.5 (was 4.0.4)
Installing activemodel 4.0.5 (was 4.0.4)
Using activerecord-deprecated_finders 1.0.3
Installing activerecord 4.0.5 (was 4.0.4)
Installing railties 4.0.5 (was 4.0.4)
Installing rails 4.0.5 (was 4.0.4)
Your bundle is updated!

Question: Is this the expected behaviour? According to another user, I expected to see what is locking the version.

Question: Why was rails locked? And is there a better way of dealing with this situation than what I did?

Community
  • 1
  • 1
user664833
  • 18,397
  • 19
  • 91
  • 140

1 Answers1

21

Is this the expected behaviour?

Yes. Gems have dependencies. When you update a gem, it gets its updated dependencies (in case of rails, it is its active* parts, for example).

This is an output of successful bundle update, by the way. Which means that there were no conflicts in dependency resolution. If there were a conflict, you'd see that instead. (something like 'gem A requires gem B v1.2.3, but gem C uses gem B v4.5.6').

Why was rails locked?

Because Gemfile.lock specified rails version 4.0.4. And it is this version (from lock file) that will be used by bundler, on deploys, etc. Simply changing version in a Gemfile will not affect which gem version is loaded. bundle install / bundle update is needed.

Update

Useful link: http://viget.com/extend/bundler-best-practices

Here are the rules:

  1. Always use bundle install
  2. If you need to upgrade a dependency that Bundler is already managing, use bundle update gem_name.
  3. Don't run bundle update unless you want all of your gems to be upgraded.
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
  • 1
    Hmm.. maybe I still don't understand. I have updated gems in the passed, and I don't recall having to run `bundle update gem_name` - I just always run `bundle` (no arguments) which is equivalent to `bundle install` ([until bundler `v2` comes out some day](https://github.com/bundler/bundler/issues/1452)). Just now I was on an update streak, and updated seven other gems, one at a time, and have been able to just update the version in `Gemfile` and run `bundle`. It turns out that just now I was forced to run `bundle update jquery-rails` and I realized that, actually, I still don't understand why. – user664833 May 28 '14 at 07:40
  • The messages `You have requested: rails = 4.0.5` and `The bundle currently has rails locked at 4.0.4.` do not suggest conflict. Same for `jquery-rails` - I got similar messages: `You have requested: jquery-rails ~> 3.1.0` and `The bundle currently has jquery-rails locked at 3.0.4.` -- In both cases, running `bundle update gem_name` just went ahead and updated the gems (seemingly no different than when I update gems with `bundle` (aka `bundle install`)). I would love to know what is really going on. I have read a bunch of blogs and answers online, and I have yet to find a satisfying answer. – user664833 May 28 '14 at 07:56
  • @user664833: at this point, your best source is bundler source code, I think. The only definitive answer is there :) – Sergio Tulentsev May 28 '14 at 07:59
  • 2
    Ok, I will have to follow up. I just want to mention that I am speaking with all due respect, and I sincerely value your answer and comments. Your answer to *Why was rails locked?* was *Because `Gemfile.lock` specified rails version `4.0.4`.* Well, every gem is specified in `Gemfile.lock` with a version. For example, I see no difference between `rails` and `passenger`, yet `rails` requires `bundle update rails` to get updated and `passenger` is fine with just `bundle install`. Note: I use `~>` for every gem in `Gemfile` except `rails`. But again `jquery-rails` said it was *locked*. So strange. – user664833 May 28 '14 at 08:17
  • This is what happened when I tried to run `bundle install` after changing rails version: http://monosnap.com/image/ZZXsruvU5N7nazHbNYAvJ0V5w41wb8.png I can't reproduce that "gem is locked" scenario, so I took an educated guess. Maybe has something to do with deployment mode (are you, by any chance, trying to update rails version on a deployed production, or something)? – Sergio Tulentsev May 28 '14 at 08:29
  • I am updating in `development` world - *not* deployed, *not* production. – user664833 May 28 '14 at 08:52