LoginSignup
25
15

More than 5 years have passed since last update.

gem install pg でエラーがでた

Last updated at Posted at 2016-01-06

bundle installしたときに、gem 'pg' でエラーが出ました。
エラーが出た環境は、Ubuntu 15.04です。Ruby環境はrbenvを使って、ruby 2.2.2を使っています。
ネットを検索しても'pg_config.libpq-dev'について書いているものがなかったので、備忘録として書いておきます。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...省略...
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
...省略...

libpq-fe.hが見つからないようです。

$ apt-file update
$ apt-file search libpq-fe.h
libpq-dev: /usr/include/postgresql/libpq-fe.h
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h

libpq-dev はインストールしています。
/usr/bin/pg_config を見にいってみ見つかっていないようです・・・。

$ ls -l /usr/bin/pg*
-rwxr-xr-x 1 root root 39728  8月  5 10:25 /usr/bin/pg
-rwxr-xr-x 1 root root 30760  8月 21  2014 /usr/bin/pg_config
-rwxr-xr-x 1 root root 30792 10月 10 11:41 /usr/bin/pg_config.libpq-dev
-rwxr-xr-x 1 root root 27216  2月 11  2015 /usr/bin/pgrep

おや、pg_config.libpq-dev なんてものがあるぞ・・・。
これか!

$ gem install pg -v '0.18.2' -- --with-pg-config=/usr/bin/pg_config.libpq-dev
$ rbenv rehash

通った・・・。
それでは、bundle install が通るように設定したいと思います。

$ bundle config build.pg --with-pg-config=/usr/bin/pg_config.libpq-dev
$ bundle install
$ rbenv rehash

with-pg-config もGemfileに書けたらいいのですが。

以上、gem 'pg' エラーの対応でした。

25
15
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
15