capistranoで発行しようとしてbundle install でエラー。
どハマりしたのでメモ。
環境
- CentOS Linux release 7.1.1503 (Core)
エラー内容
Tasks: TOP => deploy:updated => bundler:install (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing on host conohaprod: bundle exit status: 5 bundle stdout: 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. bundle stderr: Nothing written
言われるがままgem installしてみる。
$ gem install pg -v '0.17.1' Fetching: pg-0.17.1.gem (100%) Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /home/unityroom_production/.rbenv/versions/2.2.2/bin/ruby -r ./siteconf20151213-13863-1v1d25d.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. 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/unityroom_production/.rbenv/versions/2.2.2/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/unityroom_production/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/pg-0.17.1 for inspection. Results logged to /home/unityroom_production/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/pg-0.17.1/gem_make.out
2つエラーしてる?
checking for pg_config... no
checking for libpq-fe.h... no
対応
とりあえずcapistranoは忘れて手作業でbundle installを通す。
参考:Ruby - gem install pgしてNo pg_configとなる対処法 - Qiita
この記事でbundleに--with-pg-configを渡す方法が書かれてた。
$ find / -name pg_config /usr/pgsql-9.4/bin/pg_config $ bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config $ bundle install
これでpg_configに対するエラーは消えた。
残すはlibpq-fe.hのみ。
参考:gem install pgでエラー……めっちゃはまった。|ALVIS
それはこっちの記事が参考になった。
# yum search postgresql-devel postgresql-devel.x86_64 : PostgreSQL development header files and libraries # yum install postgresql-devel.x86_64
$ find / -name libpq-fe.h /usr/include/libpq-fe.h $ bundle install
これでgem install pgは通った!!(別のgemでエラーしたけどw)
上記作業をansibleのplaybookに反映する必要があるけどそれはなんとかなるだろう・・・。
findコマンド初めて使ったけどちょー便利だな・・・
追記
ConohaVPSを再作成して最初からpostgresql-devel.x86_64
をインストールしたら
--with-pg-config
を指定しなくても通った。そっちが原因だったのか・・・。