ubuntsu 15.04 でgem pg install に失敗する。
原因:
libpq-fe.hが見つからないことでインストールに失敗する。
また、ubuntsu 15.04でlibpq-devをインストールしただけだとパスに乗っかってないから、やっぱりlibpq-fe.hが見つからない。
よって、gem install に使うconfigにパスを明示してやる必要性がある。
解決方法:
sudo apt-get install libpq-dev export CONFIGURE_ARGS="with-pg-include=/usr/include/postgresql/libpq-fe.h" bundle install
備忘録:
herokuのpgインストール中に下記のエラーが発生。
Installing pg 0.17.1 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150906-8484-b5czan.rb extconf.rb 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 *** 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. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/$(RUBY_BASE_NAME) --with-pg --without-pg --with-pg-config --without-pg-config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/lib extconf failed, exit code 1 Gem files will remain installed in /home/nukisashineko/.rvm/gems/ruby-2.2.3/gems/pg-0.17.1 for inspection. Results logged to /home/nukisashineko/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/pg-0.17.1/gem_make.out An error occurred while installing pg (0.17.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.
Can't find the 'libpq-fe.h header
ということで、libpq-fe.hが見つからないらしい。
こんな時のapt-fileコマンドを使って
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.
と返ってくる。
つまりlibpq-devを入れれば解決するはず・・・。
sudo apt-get install libpq-dev
やったか・・・?
gem install pg
Installing pg 0.17.1 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150906-8484-b5czan.rb extconf.rb 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 *** 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. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/$(RUBY_BASE_NAME) --with-pg --without-pg --with-pg-config --without-pg-config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/lib extconf failed, exit code 1 Gem files will remain installed in /home/nukisashineko/.rvm/gems/ruby-2.2.3/gems/pg-0.17.1 for inspection. Results logged to /home/nukisashineko/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/pg-0.17.1/gem_make.out An error occurred while installing pg (0.17.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.
くぅ、ダメか。
ネットを探し回ると、
rails install pg - Can't find the 'libpq-fe.h header - Stack Overflow
On Mac OS X run like this:
gem install pg -- --with-pg-config=/path/to/pg_config
/path/to/pg_config is path to pg_config
ruby on rails - Can't find the 'libpq-fe.h header when trying to install pg gem - Stack Overflow
export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg
というふうにライブラリの場所を直接指定してやれという回答を発掘。
さっきインストールしたlibpq-fe.hがどこにあるか調べると
sudo updatedb locate libpq-fe.h
/usr/include/postgresql/libpq-fe.h
にあるらしい。
つまり、うちのマシンでは
export CONFIGURE_ARGS="with-pg-include=/usr/include/postgresql/libpq-fe.h" gem install pg
Building native extensions. This could take a while... Successfully installed pg-0.18.3 1 gem installed
で成功する。
で、肝心の
export CONFIGURE_ARGS="with-pg-include=/usr/include/postgresql/libpq-fe.h" bundle install
でも成功することを見届けてherokuのexampleがlocalで動くことを確認。