【问题标题】:Why can't the pg gem be installed in AWS Elastic Beanstalk?为什么无法在 AWS Elastic Beanstalk 中安装 pg gem?
【发布时间】:2023-03-07 20:21:01
【问题描述】:

我正在将一个简单的应用程序部署到 AWS Elastic Beanstalk。但是,当我将 gem 'pg' 放入 Gemfile 并将这些推送到 Elastic Beanstalk 时。我的日志中出现以下错误:

-------------------------------------
/var/log/eb-tools.log
-------------------------------------
Installing actionpack (4.0.1) 
Installing mime-types (1.25) 
Installing polyglot (0.3.3) 
Installing treetop (1.4.15) 
Installing mail (2.5.4) 
Installing actionmailer (4.0.1) 
Installing activemodel (4.0.1) 
Installing activerecord-deprecated_finders (1.0.3) 
Installing arel (4.0.1) 
Installing activerecord (4.0.1) 
Installing coffee-script-source (1.6.3) 
Installing execjs (2.0.2) 
Installing coffee-script (2.2.0) 
Installing thor (0.18.1) 
Installing railties (4.0.1) 
Installing coffee-rails (4.0.1) 
Installing hike (1.2.3) 
Installing jbuilder (1.5.2) 
Installing jquery-rails (3.0.4) 
Using json (1.8.1) 
Installing pg (0.17.0) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9 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}/
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/ruby1.9
    --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}/


Gem files will remain installed in /usr/share/ruby/1.9/gems/1.9.1/gems/pg-0.17.0 for inspection.
Results logged to /usr/share/ruby/1.9/gems/1.9.1/gems/pg-0.17.0/ext/gem_make.out
An error occurred while installing pg (0.17.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.0'` succeeds before bundling.
ERROR: bundle install failed!

2013-11-17 14:10:03,371 [ERROR] (8302 MainThread) [directoryHooksExecutor.py-34] [root directoryHooksExecutor error] Script failed with returncode 1
2013-11-17 14:10:03,499 [INFO] (8269 MainThread) [command.py-130] [root command execute] Command returned: (code: 1, stdout: Error occurred during build: Command hooks failed
, stderr: None)
....

我在本地没有错误。

很久以前,我记得在我的其他 Ubuntu 机器上遇到过这个问题。显然,需要通过sudo apt-get install ruby-dev build-essentialsudo apt-get install postgresql-client libpq5 libpq-dev 安装其他库。我会试一试,但在 AWS Elastic Beanstalk 上,我不太确定如何执行此操作。

【问题讨论】:

    标签: ruby-on-rails amazon-web-services amazon-elastic-beanstalk pg


    【解决方案1】:

    .ebextensions/packages.config:

    packages:
      yum:
        postgresql-devel: []
    

    这将确保任何新实例都安装了这个库

    【讨论】:

    • 你是如何解决这个问题的找不到'libpq-fe.h header?过去三天让我发疯。请帮忙!
    • 感谢它的工作。唯一的问题是我的 git 命令根本没有跟踪 .ebextensions/p.config 文件。
    • 所以这意味着在 AWS Elastic Beanstalk 上,您需要 postgresql-devel,而不是 libpq-dev。这确实有效,谢谢。对于那些不知道的人,.ebextensions/packages.config 在您自己的源代码包中创建的目录和文件:请参阅docs.aws.amazon.com/elasticbeanstalk/latest/dg/…
    【解决方案2】:

    添加

    packages:
      yum:
        postgresql93-devel: []
    

    【讨论】:

      【解决方案3】:

      .ebextensions/packages.config

      packages:
        yum:
          postgresql-devel: []
      

      需要注意的重要一点是您需要设置 postgresql-devel 以匹配您的 postgresql 版本的库。例如,如果你有 postgresql 9.4.5,你需要安装一个 postgresql-develXX。

      使用yum list,您将能够识别正确的库。

      【讨论】:

        猜你喜欢
        • 2016-11-08
        • 2020-10-13
        • 2013-02-20
        • 2015-03-16
        • 1970-01-01
        • 1970-01-01
        • 2018-07-01
        相关资源
        最近更新 更多