What is the prior knowledge, Gemfile, Gemfile.lock, and Bundler needed to understand these two? I will write about.
A gem that manages a gem.
Thanks to Bundler, you can use
bundle install </ code> and
bundle update </ code>.
An image like a "blueprint" for installing gem.
An image like the "result diagram" after actually installing the gem. Since gems are often related to each other, necessary gems are generated in addition to the gems described in the gemfile. In that case, Bundler will automatically install the required gem and write it in Gemfile.lock.
Gemfile is a blueprint. Only the gem to install is described. Also, gems related to gems are not described, and the versions of gems installed in the production environment and the development environment cannot be unified. However, by using Gemfile.lock, you can use the same gem and gem version in any environment.
Now that I have gained prior knowledge, I will move on to the main subject.
bundle install Install gem based on Gemfile.lock. At this time, if there is a gem that is not described in Gemfile.lock and is described in Gemfile, install that gem and the gem related to that gem, and then install Gemfile.lock.
bundle update Install gem based on Gemfile. Then update Gemfile.lock.
bundle install </ code> → Used when writing a new gem in a new environment or Gemfile.
bundle update </ code> → Used when updating the gem version. (Because bundle install does not update the gem in Gemfile.lock)
bundle install </ code> refers to Gemfile.lock to install the gem. Also,
If Gemfile.lock does not exist, create Gemfile.lock after installing gem based on Gemfile.
bundle update </ code> ignores Gemfile.lock, installs gem based on Gemfile, and then updates Gemfile.lock.
-Since Gemfile.lock is ignored, unlike
bundle install </ code>, the dependency (version etc.) between gems is renewed.
I see. Basically, it seems that bundle install is often used during actual development. Use with caution when using bundle update.