After running the bundle install command, \'Gemfile.lock\' is created in the working directory. What do the directives inside that file mean?
F
Bundler is a Gem manager which provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.
Gemfile and Gemfile.lock are primary products given by Bundler gem (Bundler itself is a gem).
Gemfile contains your project dependency on gem(s), that you manually mention with version(s) specified, but those gem(s) inturn depends on other gem(s) which is resolved by bundler automatically.
Gemfile.lock contain complete snapshot of all the gem(s) in Gemfile along with there associated dependency.
When you first call bundle install, it will create this Gemfile.lock and uses this file in all subsequent calls to bundle install, which ensures that you have all the dependencies installed and will skip dependency installation.
Same happens when you share your code with different machines
You share your Gemfile.lock along with Gemfile, when you run bundle install on other machine it will refer to your Gemfile.lock and skip dependency resolution step, instead it will install all of the same dependent gem(s) that you used on the original machine, which maintains consistency across multiple machines
Why do we need to maintain consistency along multiple machines ?
Running different versions on different machines could lead to broken code
Suppose, your app used the version 1.5.3 and it works 14 months ago
without any problems, and you try to install on different machine
without Gemfile.lock now you get the version 1.5.8. Maybe it's broken
with the latest version of some gem(s) and your application will
fail. Maintaining consistency is of utmost importance (preferred
practice).
It is also possible to update gem(s) in Gemfile.lock by using bundle update.
This is based on the concept of conservative updating