Last Updated: February 25, 2016
·
2.133K
· simaob

Bundle config: Passing parameters to your gems installation

When trying to deploy a Ruby on Rails application with capistrano to a new server I was getting an error when bundle tried to install the pg gem. It was failing to build the gem's native extension because it couldn't find the path to pg_config.

The pg error message kindly advised me on how to specify the pg_config path, but I needed bundler to know this and not the gem install command.

With a quick search I came across bundle config. This tool lets you append parameters to the install command of a specific gem. All you need to do is run the following command:

bundle config build.pg --with-pg-config=/usr/local/pgsql/bin/pg_config

Which adds the config information into ~/.bundle/config:

BUNDLE_BUILD__PG: --with-pg-config=/usr/local/pgsql/bin/pg_config

This option could also be passed into the bundle install command, but in the case of the pg gem the path will be the same across applications, so I believe that having it globally in the server is the best option.