pg gem 安装在 Redhat 中出现错误

pg gem installation is giving error in Redhat

我正在执行 gem install pg 安装 pg,然后在 Redhat AWS 机器上执行 chef 脚本。我收到以下错误:

gem install pg Building native extensions. This could take a while...
ERROR:  Error installing pg:
       ERROR: Failed to build gem native extension.

current directory: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/pg-1.1.4/ext/opt/chef/embedded/bin/ruby -r ./siteconf20190924-20230-k0ngu5.rb extconf.rb
checking for pg_config... yes
Using config values from /bin/pg_config
checking for libpq-fe.h...
*** 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
       --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=/opt/chef/embedded/bin/$(RUBY_BASE_NAME)
       --with-pg
       --without-pg
       --enable-windows-cross
       --disable-windows-cross
       --with-pg-config
       --without-pg-config
       --with-pg_config
       --without-pg_config
       --with-pg-dir
       --without-pg-dir
       --with-pg-include=${pg-dir}/include
       --with-pg-lib
       --without-pg-lib=${pg-dir}/lib

/opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:601:in `try_cpp'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:1162:in `block in find_header'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:959:in `block in checking_for'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:350:in `block (2 levels) in postpone'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:320:in `open'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:350:in `block in postpone'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:320:in `open'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:346:in `postpone'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:958:in `checking_for'
       from /opt/chef/embedded/lib/ruby/2.5.0/mkmf.rb:1161:in `find_header'
       from extconf.rb:54:in `<main>'

To see why this extension failed to compile, please check the mkmf.log
which can be found here:

/opt/chef/embedded/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0/pg-1.1.4/mkmf.log

extconf failed, exit code 1

我正在用 root 用户尝试这个。我也使用 yum 安装了 postgresql-devel,并尝试在 libpq-fe.h 所在的位置提供 --with-pg-include(在其他一些帖子中建议),但无法解决问题。

您首先需要安装构建工具(即 C 编译器和相关工具)以及 postgres 服务器的开发头文件才能编译 gem。

对于 RedHat,您应该能够通过

获得所有必需的工具
yum install autoconf bison flex gcc gcc-c++ gettext kernel-devel make m4 ncurses-devel patch
yum install postgresql-devel

对于 Chef 14,您可以使用内置的 build_essential resource to install the required compiler packages. On older versions, you can use the build-essential cookbook