I am executing gem install pg
to install the pg and execute chef scripts afterwards in Redhat AWS machine. I am getting following error:
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
I am trying this with root user. I have installed postgresql-devel
too using yum and tried to provide --with-pg-include
too where libpq-fe.h
resides (suggested in some other posts) but couldn't resolve the issue.
You first need to install build tools (i.e. a C compiler and related tools) as well as development headers for your postgres server to be able to compile the gem.
For RedHat, you should be able to get all required tools with
yum install autoconf bison flex gcc gcc-c++ gettext kernel-devel make m4 ncurses-devel patch
yum install postgresql-devel
With Chef 14, you can use the built-in build_essential
resource to install the required compiler packages. On older versions, you can use the build-essential
cookbook.