0

I am a beginner in Ruby on Rails and I'm Using Rails4

What is the difference between Gemfile and Gemfile.lock in Rails?

Pierre-Louis Gottfrois
  • 17,561
  • 8
  • 47
  • 71
Sooraj Chandu
  • 1,348
  • 16
  • 35

2 Answers2

4

Gemfile contains the gems that will be included in your project once you run bundle install. You can group them, as well as specify their origin (where they will be fetched from), and version/branch.

Gemfile.lock is generated by bundler and contains a list of all the gems which are actually installed and their version, and including all their dependencies.

Miotsu
  • 1,776
  • 18
  • 30
2

Gemfile stores list of packages you want to install for your project, with optional informations where to find them and which version to use. If you don't have Gemfile.lock, bundler will use informations from Gemfile and find packages and versions which can be installed to satisfy all dependencies.

Gemfile.lock is then generated to store packages and their versions used by bundle install (after dependencies are resolved). If someone would invoke bundle install again, bundler checks if Gemfile.lock is up to date and if it is, bundler uses versions from Gemfile.lock to install gems.

Gemfile is used to store required packages you want to use, Gemfile.lock stores all package names and versions used with last bundle install, which should work on deployment or on other developer`s machines (because they are the same versions you used in development).

Please refer to documentation: http://bundler.io/v1.3/man/bundle-install.1.html and http://bundler.io/v1.3/man/bundle-update.1.html. Check also section about deployment.

UPDATE:

Also in Related questions: What is the difference between Gemfile and Gemfile.lock in Ruby on Rails

Community
  • 1
  • 1
MBO
  • 30,379
  • 5
  • 50
  • 52