This was reported upstream to bundler here ruby/rubygems#9218 which includes a reproduction application https://github.com/schneems/bundler-4.0-fails-with-binstub-bundle-clean. More information at those links.
The short recap is that when bundler 4.0 is executed via bin/bundle binstub, it will correctly bundle install, however running bundle clean causes it to remove itself and then in production it falls back to the default version of bundler that ships with Ruby (Ruby 3.4.8 ships with bundler 2.6.9).
While rails no longer generates a bin/bundle binstub rails/rails#54687, lots of pre-existing apps have this file. The suggestion for anyone affected by this issue right now is to remove the bin/bundle binstub from your app and check that result into git:
$ rm bin/bundle
$ git add .
$ git commit -m "Remove bin/bundle binstub"
While this seems to be an "upstream" issue in bundler, I'm opening this issue on the Ruby buildpack in case the underlying behavior cannot be fixed quickly (or at all) and the buildpack needs to introduce warning or error behavior to fail when bundler 4.0+ is used with a bin/bundle binstub.
Update 2025-12-26: This behavior is consistent with older versions of Bundler when using Ruby with a default Bundler version. It's a regression from Ruby 2.5 with bundler 2.3.27. I do not know the mechanism that prevents bundler from removing itself with that combination.
This was reported upstream to bundler here ruby/rubygems#9218 which includes a reproduction application https://github.com/schneems/bundler-4.0-fails-with-binstub-bundle-clean. More information at those links.
The short recap is that when bundler 4.0 is executed via
bin/bundlebinstub, it will correctlybundle install, however runningbundle cleancauses it to remove itself and then in production it falls back to the default version of bundler that ships with Ruby (Ruby 3.4.8 ships with bundler 2.6.9).While rails no longer generates a
bin/bundlebinstub rails/rails#54687, lots of pre-existing apps have this file. The suggestion for anyone affected by this issue right now is to remove thebin/bundlebinstub from your app and check that result into git:While this seems to be an "upstream" issue in bundler, I'm opening this issue on the Ruby buildpack in case the underlying behavior cannot be fixed quickly (or at all) and the buildpack needs to introduce warning or error behavior to fail when bundler 4.0+ is used with a
bin/bundlebinstub.Update 2025-12-26: This behavior is consistent with older versions of Bundler when using Ruby with a default Bundler version. It's a regression from Ruby 2.5 with bundler 2.3.27. I do not know the mechanism that prevents bundler from removing itself with that combination.