If you look at Ruby's beginner's article, you'll see a statement that seems to be misleading about Gemfile.lock. In this article, we will look at such a thing.
First, let's review Gemfile and Gemfile.lock.
First of all, the Gemfile specified the gem to be used ** in the project. You can specify the version as well as the name of the gem. You can also specify with a width such as "more than XX" and "less than XX". Also,
gem "hoge", "~> 3.5.2"
If you write, the
hoge gem is specified to mean" 3.5.2 or more and less than 3.6.0 ".
Gemfile.lock, on the other hand, was a file generated by Bundler. With Gemfile.lock not yet present
Then, Bundler installs gem based on the description of Gemfile, but taking the above description as an example, the version that satisfies "3.5.2 or more and less than 3.6.0" of
hoge gem" Of these, select the ** highest version ** gem that actually exists. Then record the version in Gemfile.lock and install it if it is not already installed.
The following misunderstandings arise here.
Certainly that is the case in the above situations. However, you can uninstall the gem after it has been generated. Also, in team development etc., Gemfile.lock created in someone's environment may be managed by Git and come to you. In this case, the gem written there may not yet be installed here. You may also have a version of gem installed that isn't listed in Gemfile.lock.
This shows that the description of Gemfile.lock and the installed gem (version) (in your environment) are irrelevant. You can think of Gemfile.lock as describing "** gem (version) that you are currently using ** in that project".
Next, a common misconception is
bundle installwill install gem according to Gemfile.lock.
It's fairly correct, but if it's already installed, it won't be installed (obviously), and in some cases it doesn't even follow Gemfile.lock.
That is when the version written in Gemfile.lock does not meet the conditions for the version written in Gemfile.
For example, if Gemfile.lock is
1.0.3 and you rewrite Gemfile as
> = 1.1,
bundle install will not adopt
> = 1.1. The version that satisfies is selected and Gemfile.lock will be rewritten.
The relationship between Gemfile and Gemfile.lock is a bit complicated.