【问题标题】:pg gem install fails, cannot find libpq-fe.h headerpg gem 安装失败,找不到 libpq-fe.h 头文件
【发布时间】:2015-05-03 01:59:43
【问题描述】:

每当我在我的 VPS(CentOS Linux 版本 7.0.1406 (Core))上运行 bundle install 时,安装 pg gem 时都会出错。

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.

我可以使用 gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config 独立安装 pg,问题已解决。

所以我添加了一个 capistrano 任务来创建一个 ./bundle/config 用于部署,其中 build.pg 键设置为我的 VPS 上的 pg_config 路径。在 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* gems

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)

使用捆绑器成功安装 pg 我在这里缺少什么?如果您需要任何其他信息,请发表评论,我会更新这篇文章。

【问题讨论】:

    标签: centos capistrano bundler pg centos7


    【解决方案1】:

    postgres 二进制文件不在路径中。将它们符号链接到路径中的目录,你应该很好:ln -s /usr/pgsql-9.4/bin/p* /usr/local/bin

    您是构建 postgres 还是从 yum 安装它?

    【讨论】:

    • 您的自定义任务能否成功且独立地通过 Capistrano 运行? Capistrano 有什么输出?
    • 感谢您的回复:这是 capistrano 输出的要点(带调试)gist.github.com/whargrove/03ff94d1b6e7648030ed
    • :prepare_bundle_config由于使用release_path不能独立运行,所以只能在deploy任务期间使用。
    • 顺便说一句,将 postgres 二进制文件符号链接到远程用户的路径似乎已经解决了这个问题。谢谢!只要允许,我就会奖励赏金。
    • 也为我工作,我在 CentOS 7 上运行 postgresql 9.3,非常感谢
    【解决方案2】:

    我发现如果我用源代码编译 pgsql,而 PATH ENV 没有配置 pgsql/bin,就会发生这种情况。你可以试试这个。

    【讨论】:

      【解决方案3】:

      只是发布 PostgreSQL 11 的解决方案。如果有人登陆这里。

      sudo yum install epel-release
      
      sudo yum install postgresql11-llvmjit
      
      sudo yum install postgresql11-devel postgresql11-libs
      

      然后运行

      gem install pg -v '1.2.3' -- --with-pg-config=/usr/pgsql-11/bin/pg_config 
      

      就是这样

      【讨论】:

        【解决方案4】:

        或者,如果您使用的是 Mac

        brew link postgresql
        

        或者在我的情况下

        brew link postgresql@12
        

        【讨论】:

          猜你喜欢
          • 2011-08-27
          • 2012-10-16
          • 2018-10-20
          • 2011-05-22
          • 1970-01-01
          • 1970-01-01
          • 2020-03-16
          相关资源
          最近更新 更多