Discuss This Topic
There are 1 comments in this discussion.
Read and join this discussion
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.
Walter McGinnis
said Use of bundler zsh plugin
If you use zsh and oh-my-zsh, an alternative to add ./bin to you path is to simply use the bundler plugin.
In a project that uses bundler (ruby, commonly rails), it will check for the command (from a list in the plugin) under ./bin for you and use that executable. If it is not present, it will call it with "bundle exec" prefixed.
Tags: Ruby, Rails, bundler, tips, tricks, zsh, oh-my-zsh