From 57c4954d6f4ef0762d165786c5d0732d64d56338 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 26 Dec 2025 11:33:07 -0600 Subject: [PATCH] Add Regenerate Lock File With Newer Bundler as a Ruby TIL --- README.md | 3 +- ...regenerate-lock-file-with-newer-bundler.md | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 ruby/regenerate-lock-file-with-newer-bundler.md diff --git a/README.md b/README.md index 7ed30ba..0ffce9b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter). -_1710 TILs and counting..._ +_1711 TILs and counting..._ See some of the other learning resources I work on: @@ -1445,6 +1445,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Read The First Line From A File](ruby/read-the-first-line-from-a-file.md) - [Refer To Implicit Block Argument With It](ruby/refer-to-implicit-block-argument-with-it.md) - [Reference Hash Key With Safe Navigation](ruby/reference-hash-key-with-safe-navigation.md) +- [Regenerate Lock File With Newer Bundler](ruby/regenerate-lock-file-with-newer-bundler.md) - [Rendering ERB](ruby/rendering-erb.md) - [Replace The Current Process With An External Command](ruby/replace-the-current-process-with-an-external-command.md) - [Require Entire Gemfile In Pry Session](ruby/require-entire-gemfile-in-pry-session.md) diff --git a/ruby/regenerate-lock-file-with-newer-bundler.md b/ruby/regenerate-lock-file-with-newer-bundler.md new file mode 100644 index 0000000..34ea24e --- /dev/null +++ b/ruby/regenerate-lock-file-with-newer-bundler.md @@ -0,0 +1,34 @@ +# Regenerate Lock File With Newer Bundler + +While upgrading to the latest Ruby version (4.0.0), I also wanted to upgrade the +version of `bundler` that my project uses. This shows up at the bottom of the +`Gemfile.lock` file as the `BUNDLED WITH` line. Despite installing the latest +version of `bundler`, I get the following message when I try to install +dependencies. + +```bash +$ bundle install + +Bundler 4.0.3 is running, but your lockfile was generated with 2.6.2. +Installing Bundler 2.6.2 and restarting using that version. +... +``` + +Instead, what we need to tell `bundle` to update the locked version of `bundler` +in the `Gemfile.lock`. + +```bash +$ bundle update --bundler + +Fetching gem metadata from https://rubygems.org/......... +Resolving dependencies... +Bundle updated! +``` + +The `--bundler` flag for `bundle-update` says the following: + +> Update the locked version of bundler to the invoked bundler version. + +So we could pass a specific `bundler` version to that flag, but in this case I +want to use the version I'm invoking it with which is the latest that I just +installed.