Bundler 2.3 honors the version specified in `BUNDLED_WITH`

Updated . Posted . Visible to the public.

Bundler so far ignored the version specified under BUNDLED_WITH in the Gemfile.lock. This had two annoying consequences:

  • If the bundler version on your system was lower than in the Gemfile.lock, you got an error message and had to manually install the correct version.
  • If the bundler version on your system was higher than in the Gemfile.lock, bundler silently updated the version in the Gemfile.lock to your system's bundler version. To avoid this, you had to always specify, which version you want to use for each bundler command, e.g. bundler _2.1.4_ update

New behavior

Bundler now honors the version specified under BUNDLED_WITH in the Gemfile.lock. The necessary version will automatically be installed, if missing.
This requires bundler 2.3 and rubygems 3.3
For more details, see: https://bundler.io/blog/2022/01/23/bundler-v2-3.html Show archive.org snapshot

Suggested bundler version

If you don't need to support older Ruby versions, simply use the newest bundler version.
If you e.g. need to support Ruby 2.5, you need an older bundler version. Bundler 2.3.0 has some deprecation warnings, so I recommend to use at least 2.3.1

Updating bundler

Determine your currently used bundler version:

bundler -v

Caution: this might already be influenced by a Gemfile.lock in your current directory. Run this command in two projects with different bundler versions in their Gemfile.lock and see if your bundler versions changes automatically. Then you probably already have the new versions.

Install a new bundler version:

# specific version
gem install bundler:2.3.11

# newest version
gem install bundler

I recommend to execute the previous command in the parent folder of all your git repos.

Updating rubygems

Determine the installed version:

gem --version

Update your rubygems version

gem update --system

Updating the bundler version for a project

With the new behavior bundler should never update its version in a Gemfile.lock automatically anymore. Therefore, unless there are reasons for using an older version, it is recommended to upgrade the bundler version for each project manually every once in a while. Good occasions would be the start and end of a development block.

Update the bundler version under BUNDLED_WITH in the Gemfile.lock:

bundle update --bundler
Klaus Weidinger
Last edit
Klaus Weidinger
License
Source code in this card is licensed under the MIT License.
Posted by Klaus Weidinger to makandra dev (2023-01-16 17:34)