7

Should I add the version for each gem in my Gemfile? Is it a best practice? Just recommended?

AdamT
  • 6,405
  • 10
  • 49
  • 75

3 Answers3

6

I do prefer to have all my gems locked to a specific version in production. Considering there might be newer versions that break compatibility with other gems or deprecate some APIs, you want to be 100% sure that you won't get surprisingly broken app when you deploy because of gem inconsistencies. Updating gems should only be done locally in development, by updating their Gemfile entries and testing each new version against the rest of you code and libraries.

svilenv
  • 1,484
  • 1
  • 11
  • 13
  • Also, sometimes there's the opposite case of having to grab the latest version available on source, because it contains a badly needed fix not available in the numbered releases. (happened to will_paginate at some time) – prusswan Jul 06 '12 at 13:36
2

Generally, you don't need to except when instructed to do so (either by the gem author, or feedback from users due to incompatibilities). Occasionally you may be using the edge version of certain gems so it does not matter anyway:

# Bundle edge Rails instead:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel',  :git => 'git://github.com/rails/arel.git'
gem "rack", :git => "git://github.com/rack/rack.git"
prusswan
  • 6,853
  • 4
  • 40
  • 61
2

I don't think you should specify version of the each gem, since versions of the current working gems already specified at Gemfile.lock .

Also if you do that, bundle update command would be useless. You should be able to use this command to update the gems. if tests pass and your application continues to work properly, just commit the new Gemfile.lock

Oguz Bilgic
  • 3,392
  • 5
  • 36
  • 59
  • `Gemfile.lock` is entirely generated from the rules specified in `Gemfile` and the last `bundle update`, so only `Gemfile` has to be considered, no matter the versions are specified or not. – prusswan Jul 06 '12 at 13:34
  • that's what i am saying too... You should not specify versions of the each gem so `bundle update` can update some of them – Oguz Bilgic Jul 06 '12 at 14:48