Using Bundler for Playing with Ruby Gems

I often want to experiment with a Ruby gem, but don’t want to install it (and all its dependencies) globally on my system. So, I use Bundler to install and use it locally in the project directory. That way I can easily clean the whole thing up when I’m done.

For example, I recently wanted to check out Octopress 3, to see what the genesis-theme looks like.

Just start in an empty project dir, and create a Gemfile that looks like:

source ''

gem 'octopress', '~> 3.0'
group :jekyll_plugins do
  gem 'octopress-genesis-theme'

Now install the gems using bundler. The --path=vendor is the key that installs everything into the local dir (in a subdir named vendor, to be specific). Once you run it this way once, it creates a .bundle/config file that remembers this setting for subsequent invocations of bundle.

$ bundle install --path=vendor
Resolving dependencies...
Using execjs 2.5.2
Using autoprefixer-rails
Using blankslate
# lots more gems and versions…
Bundle complete! 2 Gemfile dependencies, 61 gems now installed.
Bundled gems are installed into ./vendor.

Now you just have to prefix the commands that want to use the gem exectuables with bundle exec.

$ bundle exec octopress new . --force
$ cat >> _config.yml
exclude: [vendor]
$ bundle exec jekyll serve

Then, when I’m done tinkering, I can delete the whole project dir, and not be left with a bunch of cruft installed in my system.