ruby / ruby/rubygems

Binstub with bundle path configured loads wrong version of Bundler

Open
#6,883 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bundler
Dominant language
Ruby
Stars
4k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
81

Description

On the latest version of bundler (2.4.18), but I think this applies to all versions, we noticed a bug(?) wherein if you have path configured, a binstub (using require "bundler/setup") boots into the wrong version of Bundler. More specifically, it just uses your system bundler instead of the higher versioned bundler installed (into say, vendor/bundle) and specified by your Gemfile.lock.

We noticed this problem in our Docker image where Ruby 3.2.2 comes with Bundler 2.4.10. We install gems in our docker image to vendor/bundle. If you run bin/rails (or any binstub) and puts Bundler::VERSION inside the process, you'll get 2.4.10 instead of 2.4.18.

This is easily reproducible locally:

  1. bundle install --path vendor/bundle
  2. gem uninstall bundler (this is to uninstall the higher version of bundler from your system gems. It should be installed into vendor/bundle already).
  3. bin/rails runner "puts Bundler::VERSION"

I thought that this was by design since I don't even see how we would load Bundler (whichever one is available), then realize that we've installed gems into a custom path, then switch over to the right version of bundler all within the same process. But then I saw @indirect's blog post: Never bundle exec again and thought, maybe this is an oversight.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with bundle install --path vendor/bundle, removal of the higher system Bundler, and bin/rails runner "puts Bundler::VERSION". Start by tracing how the binstub's require "bundler/setup" selects Bundler when gems are installed under vendor/bundle; done means the binstub loads the version specified by Gemfile.lock rather than the system version.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.