Rails quick tips #3: Adding a Gemfile.dev

- ruby rails tips bundler

We all know the problem: different developers prefer different libraries, especially for their development workflow. However, for various reasons we may not just want to add them unconditionally to our application’s Gemfile:

For this reason I generally add a Gemfile.dev entry to my .gitignore, which every developer can customize to their heart’s content with a list of gems that fit their workflow but may not be interesting to/wanted by other people on the same team. A trivial example looks like this:

eval_gemfile 'Gemfile'

gem 'awesome_print'

Here eval_gemfile ensures that all gems from the main Gemfile will be included in the local development bundle and then we add awesome_print on top of it.

Now we can go ahead and use either of the following two commands to install our gems and create a Gemfile.dev.lock:

$ bundle install --gemfile=Gemfile.dev
# or
$ BUNDLE_GEMFILE=Gemfile.dev bundle

I generally prefer the form using the BUNDLE_GEMFILE environment variable, since it works for all use cases (e.g. BUNDLE_GEMFILE=Gemfile.dev rails c). Of course this is a lot of extra typing, so you can use aliases, direnv or even a gemfile configuration option in ./bundle/config to make the process easier.