Skip to content

Prefer binstubs over bundle exec#6874

Open
pablobm wants to merge 1 commit intoopenstreetmap:masterfrom
pablobm:binstubs-over-bundle-exec
Open

Prefer binstubs over bundle exec#6874
pablobm wants to merge 1 commit intoopenstreetmap:masterfrom
pablobm:binstubs-over-bundle-exec

Conversation

@pablobm
Copy link
Copy Markdown
Contributor

@pablobm pablobm commented Mar 10, 2026

This is a proposal to use binstubs over bundle exec:

  1. It's the form used in the Rails Guides, and therefore should be better known to new contributors.
  2. It is clearer that we are running scripts bundled with the app.
  3. Some binstubs don't even require Bundler to work: setup, yarn, dev.
  4. Saves a few characters!
  5. It's more autocomplete-friendly.

Notes:

  • This adds some missing binstubs, which I created with bundle binstubs.
  • Also deleted the existing bin/bundle. It's not present in new Rails apps, and it's not the same one you get with bundle binstubs bundler. As a result it was triggering the error "Your bin/bundle was not generated by Bundler, so this binstub cannot run". You can see the responsible check in any Bundler-dependent binstubs like the ones added here.
  • bundle exec bin/yarn install is simplified to bin/yarn install, which was a bit excessive :-)
  • I have changed the one instance in the comment at config/initializers/doorkeeper.rb, even though that's still generated in that form by Doorkeeper.

@pablobm pablobm marked this pull request as draft March 10, 2026 14:46
@pablobm pablobm force-pushed the binstubs-over-bundle-exec branch 2 times, most recently from 0c2e819 to 365a3ff Compare March 11, 2026 10:53
@pablobm pablobm force-pushed the binstubs-over-bundle-exec branch from 365a3ff to df89052 Compare March 11, 2026 10:54
@pablobm pablobm marked this pull request as ready for review March 11, 2026 11:18
@pablobm
Copy link
Copy Markdown
Contributor Author

pablobm commented Mar 11, 2026

This is reviewable now.

Comment thread bin/danger
Copy link
Copy Markdown
Member

@Firefishy Firefishy Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this file generated by bundler or by the gem? Isn't there a risk that it changes in the future?

bundle exec might not be the most elegant, but for me it has been the most reliable way to execute the gem bin across different developer setups.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically all of them could change. However they are only a layer of boilerplate, the same for all (all that require Bundler), and only the last line is important.

The binstubs are generated by Bundler, rather than the individual applications. If it changes, it should change for all of them at the same time and... er... oh, what do you know, I just checked now, it changed recently and we are on an old version 😅 Looks like all that noisy check for the bundle executable was removed at ruby/rubygems#8345 Also reminds me that we are on an old version of Bundler...

As for the possibility of this being less reliable than bundle exec:

  • Theoretically, it should work better because it removes a layer of indirection.
  • But I understand that things work in mysterious ways so I cannot guarantee it. Just for a data point: have you had bad experiences running bin/rails or similar?

@gravitystorm
Copy link
Copy Markdown
Collaborator

gravitystorm commented Mar 11, 2026

Thanks @pablobm . I think I need to mull over this because I have an initial reaction against it.

  1. It's the form used in the Rails Guides, and therefore should be better known to new contributors.

That's a good reason.

2. It is clearer that we are running scripts bundled with the app.

I think it's a bit confusing though, since most of the things are coming from 3rd-party software. So we're just adding wrappers and adding indirection

5. It's more autocomplete-friendly.

Do you mean that autocomplete as in bin/anno<tab> works whereas bundle exec anno<tab> doesn't? Perhaps that's worthwhile too.


The downsides I see are:

  • Using bundle exec is common across many non-rails projects, like running jekyll sites etc. It's certainly in my own muscle memory!
  • bundle exec allows you to run anything from any gem that you have installed, without having to create/maintain any binstubs

@pablobm
Copy link
Copy Markdown
Contributor Author

pablobm commented Mar 12, 2026

Re: autocomplete, yes, I'm referring to bin/anno<tab>.

Re: layers of indirection, my impression is that it's lower with binstubs. For example, looking at bin/rails, it goes straight into config/application, while the bundle exec version goes into Bundler, which then loads $RUBY_INSTALL/ruby/4.0.1/bin/rails, which goes into more confusion. Supporting this I see reports that binstubs are slightly faster (although speed is not an argument I want to particularly rely on).

I used to be a bundle exec person, but I changed a couple of years ago (I can't remember why). Now my muscle memory is the opposite, but you are right that I still use it for a non-Rails project I have elsewhere.

I must admit that this PR started in my head a bit as a pet peeve, but when I saw what was on the guides, I decided to put it in practice. I do understand the frictions at hand, so no worries if you are not convinced.

The one thing that I think we should change definitely at the very least is bundle exec bin/yarn, which should be just bin/yarn. There's no Bundler involved there!

@hlfan
Copy link
Copy Markdown
Collaborator

hlfan commented Mar 21, 2026

For 3, 4 and #6784 (comment) something like this could also work:

bx() {
  if [ "$1" = "yarn" ] || [ "$1" = "dev" ] || [ "$1" = "setup" ]; then
    cmd="$1"
    shift
    "./bin/$cmd" "$@"
  else
    bundle exec "$@"
  fi
}

It would even be one character shorter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants