Topic: Work Tools Revamp - binstubs instead of bundle exec

Topic type:

Third installment in a series on sprucing up my text editor, shell, rubies, etc. This is a quick one that covers using binstubs rather than prefixing commands with bundle exec on ruby projects.

Update: for Rails projects, as of Rails 4-ish there's a "Rails way" of handling binstubs. See the Getting Started Guide and for background see this post.

---

For a long time I had been hearing "use binstubs" as a description of how to NOT have to prefix commands in a Rails or Ruby project with bundle exec to get the correct "bundled" environment to run them in.

I guessed that this had to do with adjusting one's PATH, but I couldn't find the exact suggested practice in the community. It is simple, but sometimes it is useful to explicitly spell things out to avoid confusion.

In the meantime, I kept using the prefix for my commands. I put off solving the problem until I understood the particular problem domain enough to solve it properly.

While looking around for stuff about rbenv, I came across Understanding Binstubs. For development in a trusted environment, the solution is simple, add ./bin to the beginning of your PATH in your environment and then use the --install-stubs whenever you do a bundle install or the like. In my case that meant updating ~/.zshenv.

DO NOT DO THIS IN PRODUCTION.

In production, simply add bundler support to your deployment tool, such as doing a require "bundler/capistrano" in your capistrano deploy.

Discuss This Topic

There are 1 comments in this discussion.

Read and join this discussion

join this discussion