RubyからPostgreSQLを利用するためのライブラリ pg のアップデート

[PostgreSQL][CentOS][MacOSX]RubyからPostgreSQLを利用するためのライブラリ pg のアップデートでエラーが出た場合の対処方法

久しぶりに書きます。

RubyからPostgreSQLを使うにはruby-pgライブラリが必要です。

ruby-pgのインストールはgemで一発です。

 gem install pg

Windowsやpg-0.8.0では問題なかったのですが MacCentOSでのpg-0.9.0へのアップデートでは、エラーになることがあります。

Mac Leopardの場合】

Updating pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for pg_config... no
  :
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.9.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.9.0/ext/gem_make.out
Nothing to update

これの対処
PATHにpg_configへのパスを追加します。

$ export PATH=/opt/local/lib/postgresql84/bin:$PATH 
MacBookPro:~ ofukui$ sudo gem update
Updating installed gems
Updating pg
Building native extensions.  This could take a while...
Successfully installed pg-0.9.0
Gems updated: pg
Installing ri documentation for pg-0.9.0...
Installing RDoc documentation for pg-0.9.0...

CentOSの場合】

Updating pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for pg_config... no
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
extconf.rb failed ***
: Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/pg-0.9.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.9.0/ext/gem_make.out Nothing to update
さしあたり pg-0.8 が動作しているので放置していたのですが、遂に解決しました。
$ sudo gem install pg -- --with-pg-config=/usr/local/pgsql/bin/pg_config
Building native extensions.  This could take a while...
Successfully installed pg-0.9.0
1 gem installed
Installing ri documentation for pg-0.9.0...
Installing RDoc documentation for pg-0.9.0...
ポイントは
 -- --with-pg-config=/usr/local/pgsql/bin/pg_config
postgresqlのプログラムであるpg_configのパスをgem installの際に付与することです。