AbstractCoder

// Web and Mobile Development Blog

Using Multiple Gemfiles

August 23, 2013

One of the major benefits of Bundler is being able to checkout a project and install its Gem dependencies using the bundle command. However, Gems that are only used locally shouldn't be added to the Gemfile because they unnecessarily alter Gem dependencies and in some cases create conflicts with project Gems.

I wanted users to be able to easily install my project's toolchain without creating conflicts so I decided to create a separate Gemfile named Gemfile.tools.

Gemfile.tools

source 'https://rubygems.org'

gem 'chef'
gem 'vagrant', '~>1.0.7'
gem 'knife-solo'

To install the Gems from this file you need to run

bundle install --gemfile Gemfile.tools

This will install the Gems and create a new file called Gemfile.tools.lock.

Finally to use the bundle exec command with the new Gemfile.tools you run

BUNDLE_GEMFILE=Gemfile.tools bundle exec ...

I find this to be a bit cumbersome so the other option is to install the Gems with binstubs

bundle install --gemfile Gemfile.tools --binstubs

Then you can access your gems through your project's bin directory

bin/...

By creating two separate Gemfiles I was able to harness the power of Bundler while keeping my project and toolchain Gems separate.

Steve Johnson

Developer, Designer
Product Bootstrapper

Site

Home
Web Development
Resources

Work

Estimate Rocket
Awesome Dash
Awesome Contact
Logical Engine
QSEI

Social

@abstractcoder
GitHub
LinkedIn