bundler and spring

some background information about bundler and spring as well as some intricacies of using bundle exec, bundler and spring binstubs.



bundle exec command executes the command, making all gems specified in the Gemfile(5) available to require in Ruby programs.

bundler setup for Rails application takes place in config/boot.rb:

ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' # Set up gems listed in the Gemfile.

also bundler is used to manage application dependencies (gemsets) - RVM provides functionality to do it as well but bundler is a better way. rbenv doesn’t manage gemsets at all in contrast to RVM.

there might be multiple versions of the same gem installed for particular ruby version but project uses gem versions from bundle (specified in Gemfile.lock).

when running commands (rake, etc.) from within project directory it’s necessary to use bundle gem versions - this can be done in 2 ways:

bundle exec

using bundle exec is okay except that it’s necessary to type it whenever you run gem commands:

bundler binstubs

alternatively generate bundler binstubs:

$ bundle install --binstubs

to make rbenv is aware of bundler binstubs use rbenv-binstubs rbenv plugin.

$ rbenv which rspec



when using bundle exec or bundler binstubs commands are not run with spring! (well, except for bundle exec rails console but this is just a weird exception)

NOTE: don’t use spring in production!

to use spring preloader:

okay, wtf to do with all this stuff about bundler and spring?