Commit 6fa7975
Prepend project bin/ to PATH in bundle exec for load-relative Ruby
When Ruby is compiled with `--enable-load-relative` (as done by mise),
RubyGems generates binstubs with a `#!/bin/sh` wrapper that resolves
`ruby` relative to the binstub directory (`exec "$bindir/ruby"`).
When `BUNDLE_PATH` is set to `vendor/bundle`, `set_path` prepends
`vendor/bundle/ruby/X.Y.Z/bin` to PATH. `bundle exec` then finds the
vendor binstub first, but since its shebang is `#!/bin/sh` (not
`#!/usr/bin/env ruby`), `ruby_shebang?` returns false and Bundler
falls back to `kernel_exec`. The OS executes the shell wrapper, which
looks for `$bindir/ruby` in the vendor bin directory — where no `ruby`
binary exists — and fails.
This fix prepends the project `bin/` directory (where Bundler generates
binstubs with `#!/usr/bin/env ruby`) to PATH before the vendor bin
path, so `Bundler.which` finds the correctly-shimmed binstub first.
The project bin/ is only added when the directory actually exists.
Fixes an interaction between load-relative Ruby builds (mise, some
asdf configurations) and `BUNDLE_PATH=vendor/bundle`.
Related: #8441
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 3e3addb commit 6fa7975
2 files changed
Lines changed: 34 additions & 0 deletions
File tree
- bundler/lib/bundler
- spec/bundler
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
345 | 348 | | |
346 | 349 | | |
347 | 350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
346 | 377 | | |
347 | 378 | | |
348 | 379 | | |
| |||
0 commit comments