2015-03-02 82 views
7

每當我在我的VPS(CentOS Linux版本7.0.1406(Core))上運行bundle install時,安裝pg gem時出現錯誤。pg gem安裝失敗,無法找到libpq-fe.h頭文件

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. 

我可以安裝pg standalone:gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config並且問題已解決。

因此,我添加了一個capistrano任務,爲部署創建一個./bundle/config,並使用在我的VPS上設置pg_config路徑的build.pg密鑰。在Capistrano config/deploy.rb這被調用before bundler:install

desc "Create bundle config" 
task :prepare_bundle_config do 
    on roles(:app) do 
    within release_path do 
     execute :bundle, 'config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config --local' 
    end 
    end 
end 

我已經安裝了必要的軟件包:

postgresql94-server.x86_64 
postgresql94-devel.x86_64 
postgresql94-libs.x86_64 
libpqxx.x86_64 
libpqxx-devel.x86_64 

這裏是Capistrano的*我已經安裝

bundle list | grep capistrano 
* capistrano (3.3.5) 
* capistrano-bundler (1.1.4) 
* capistrano-rails (1.1.2) 
* capistrano-rbenv (2.0.3) 
* capistrano-stats (1.1.1) 

缺少什麼我在這裏跟打捆成功安裝皮克寶石?如果您需要任何其他信息,請留下評論,我會更新這篇文章。

回答

18

postgres二進制文件不在路徑中。將它們符號鏈接到路徑中的目錄中,您應該很好:ln -s /usr/pgsql-9.4/bin/p* /usr/local/bin

你建立了postgres還是從yum安裝?

+0

您的自定義任務能否成功獨立運行通過Capistrano? Capistrano有什麼輸出? – JoePasq 2015-03-10 21:56:33

+0

感謝您的迴應:以下是capistrano輸出的一個要點(帶調試)https://gist.github.com/whargrove/03ff94d1b6e7648030ed – whargrove 2015-03-11 02:24:38

+0

:prepare_bundle_config不能獨立運行,因爲它使用release_path,所以它只能用在部署任務期間。 – whargrove 2015-03-11 02:26:13

0

我發現如果我編譯帶源代碼的pgsql,並且PATH ENV沒有與pgsql/bin配合,就會發生這種情況。你可以試試這個。