15 Jan 2015

I realized today that I reflexively preface all my rake tasks with “bundle exec” (aliased to “be,” or I would have carpal tunnel syndrome by now), but I don’t know exactly what “bundle exec” does.

The short answer:

bundle exec rake db:migrate

means “run these migrations in the context of the current group of installed gems.”

The (slightly) long(er) answer:

It turns out that Bundler is actually a much more narrowly focused tool than I imagined. Because I had been using it in conjunction with so many different kinds of tasks (database migrations, rails console, checking routes, etc.) I had gotten the idea that Bundler did something different for each one. In fact, Bundler is specifically for dependency management.

bundle install

generates a Gemfile.lock, which stores all the project’s gems and their current versions. This is checked into git to track changes to the gems used. After that, prefacing commands with “bundle exec” makes sure that any necessary gems for that command will be available, assuming that they’re installed correctly. Much simpler than I thought!

Read more about bundler here.

Molly Huerster

Published on 15 Jan 2015 Find me on Twitter!

blog comments powered by Disqus