[RUBY] Gemfile.lock doesn't say the version of gem you have installed

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

bundle install

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

is. 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.0.3 and > = 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.

Recommended Posts

Gemfile.lock doesn't say the version of gem you have installed
Check the version of the JDK installed and the version of the JDK enabled
If you make a mistake in the description location of Gem, delete Gemfile.lock once.
Site where you can see the version relation of spring (?)
Have you ever thought about the definition of "bad design"?
Switch the version of bundler
Switch the version of java installed by SDKMAN when moving directories
Have you ever considered the life of a params flash session?
Is the version of Elasticsearch you are using compatible with Java 11?
[Java version] The story of serialization
Check the version of Cent OS
What you are doing in the confirmation at the time of gem update
Gem list of each ruby version 2.5.x
About the version of Docker's Node.js image
[Japanese version Faker] About the gem "gimei"
Check the version of the standard Web software.
Defense Techniques When You Have to Fight the Performance of Unfamiliar Applications (Part 2)
repository The specified gem is bundle installed but not updated to the latest version
What to do if you get To install the missing version, run `gem install bundler: 2.1.4`