24

What is the purpose of "Gemfile.lock" in Rails? I have been searching around for but could not find a satisfactory answer.

Nitish Upreti
  • 6,312
  • 9
  • 50
  • 92
  • The best resource about this is definitely the article ["Clarifying the Roles of the .gemspec and Gemfile"](http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/). Reading it will clarify all your doubts about this topic. – lucapette Feb 09 '12 at 09:33

2 Answers2

26

You should read all the documentation from the bundler gem: http://gembundler.com/

THE GEMFILE.LOCK

When you run bundle install, Bundler will persist the full names and versions of all gems that you used (including dependencies of the gems specified in the Gemfile(5)) into a file called Gemfile.lock.

Bundler uses this file in all subsequent calls to bundle install, which guarantees that you always use the same exact code, even as your application moves across machines.

Because of the way dependency resolution works, even a seemingly small change (for instance, an update to a point-release of a dependency of a gem in your Gemfile(5)) can result in radically different gems being needed to satisfy all dependencies.

As a result, you SHOULD check your Gemfile.lock into version control. If you do not, every machine that checks out your repository (including your production server) will resolve all dependencies again, which will result in different versions of third-party code being used if any of the gems in the Gemfile(5) or any of their dependencies have been updated.

fuzzyalej
  • 5,903
  • 2
  • 31
  • 49
6

Gemfile.lock ensures that other developers on your app, as well as your deployment environment, use exactly the same third-party code as you just installed.

Jatin Ganhotra
  • 6,825
  • 6
  • 48
  • 71