An error occurred while installing pg の対処法

bundle インストール中、 こんなエラーが。

An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.

詳しく見てみると、 コンフィグファイルがないためにエラーを起こしてるようだ。

Installing pg 0.18.4 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/uraway/.rvm/rubies/ruby-2.1.4/bin/ruby -r ./siteconf20160130-40823-4tdd15.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

手っ取り早い解決法としては、 PostgresHomebrewを使ってインストールすれば良いらしい。

stackoverflow.com

次のコマンドでインストール。

$ brew update; brew install postgres

もう一度bundle installを実行してみるとうまくいった。

$ bundle install

Bundle complete! 5 Gemfile dependencies, 38 gems now installed.