Gem install pg fails.yum install postgresql-devel also does not resolve.

Asked 2 years ago, Updated 2 years ago, 93 views

gem install pg displays the following error:
I'm running EC2 and my operating system is Amazon Linux.

$gem install pg-v'0.20.0'
Building native extensions. This could take a while...
ERROR:Error installing pg:
    ERROR—Failed to build gem native extension.
current directory: /home/ec2-user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/pg-0.20.0/ext
/home/ec2-user/.rbenv/versions/2.4.1/bin/ruby-r./siteconf20180206-457-e5bx4w.rbextconf.rb
checking for pg_config...yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h...no
Can't find the 'libpq-fe.header
*** extconf.rb failed***
Could not create Makefile due to some reason, probably rack of necessary
libraries and/or heads.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}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/ec2-user/.rbenv/versions/2.4.1/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
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib = ${pg-dir}/lib

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

  /home/ec2-user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/pg-0.20.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/ec2-user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/pg-0.20.0 for inspection.
Results logged to/home/ec2-user/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/pg-0.20.0/gem_make.out

I did the following, but the error did not change.

$sudo yum install postgresql-develop

Also, the psql configuration file is as follows:

$ls-l/usr/bin/pg*
lrwxrwxrwx1 root root 35 February 608:47/usr/bin/pg_archivecleanup->/etc/alternates/pg_archivecleanup
lrwxrwxrwx1 root root45 February 608:36/usr/bin/pg_archivecleanup96->../../usr/lib64/pgsql96/bin/pg_archivecleanup
lrwxrwxrwx1 root root 31 December 608:47/usr/bin/pg_basebackup->/etc/alternates/pg_basebackup
lrwxrwxrwx1 root root41 December 608:36/usr/bin/pg_basebackup96->../../usr/lib64/pgsql96/bin/pg_basebackup
lrwxrwxrwx1 root root 27 February 608:47/usr/bin/pg_config->/etc/alternates/pg_config
lrwxrwxrwx1 root root 37 February 608:47 /usr/bin/pg_config92->../../usr/lib64/pgsql92/bin/pg_config
lrwxrwxrwx1 root root 37 February 608:36/usr/bin/pg_config96->../../usr/lib64/pgsql96/bin/pg_config
lrwxrwxrwx1 root root32 February 608:47/usr/bin/pg_controllata->/etc/alternates/pg_controllata
lrwxrwxrwx1 root root42 February 608:36/usr/bin/pg_controllata96->../../usr/lib64/pgsql96/bin/pg_controllata
lrwxrwxrwx1 root root24 February 608:47/usr/bin/pg_ctl->/etc/alternates/pg_ctl
lrwxrwxrwx1 root root34 February 608:36/usr/bin/pg_ctl96->../../usr/lib64/pgsql96/bin/pg_ctl
lrwxrwxrwx1 root root25 February 608:47/usr/bin/pg_dump->/etc/alternates/pg_dump
lrwxrwxrwx1 root root 35 February 608:47/usr/bin/pg_dump92->../../usr/lib64/pgsql92/bin/pg_dump
lrwxrwxrwx1 root root 35 February 608:36/usr/bin/pg_dump96->../../usr/lib64/pgsql96/bin/pg_dump
lrwxrwxrwx1 root root 28 February 608:47/usr/bin/pg_dumpall->/etc/alternates/pg_dumpall
lrwxrwxrwx1 root root38 February 608:47/usr/bin/pg_dumpall92->../../usr/lib64/pgsql92/bin/pg_dumpall
lrwxrwxrwx1 root root38 February 608:36/usr/bin/pg_dumpall96->../../usr/lib64/pgsql96/bin/pg_dumpall
lrwxrwxrwx1 root root 28 February 608:47/usr/bin/pg_isready ->/etc/alternates/pg_isready
lrwxrwxrwx1 root root38 February 608:36/usr/bin/pg_isready96->../../usr/lib64/pgsql96/bin/pg_isready
lrwxrwxrwx1 root root32 February 608:47/usr/bin/pg_receivexlog->/etc/alternates/pg_receivexlog
lrwxrwxrwx1 root root42 February 608:36/usr/bin/pg_receivexlog96->../../usr/lib64/pgsql96/bin/pg_receivexlog
lrwxrwxrwx1 root root32 February 608:47/usr/bin/pg_recvlogical->/etc/alternates/pg_recvlogical
lrwxrwxrwx1 root root42 February 608:36/usr/bin/pg_recvlogical96->../../usr/lib64/pgsql96/bin/pg_recvlogical
lrwxrwxrwx1 root root 30 February 608:47/usr/bin/pg_resetxlog ->/etc/alternates/pg_resetxlog
lrwxrwxrwx1 root root40 February 608:36/usr/bin/pg_resetxlog96->../../usr/lib64/pgsql96/bin/pg_resetxlog
lrwxrwxrwx1 root root 28 February 608:47/usr/bin/pg_restore->/etc/alternates/pg_restore
lrwxrwxrwx1 root root38 February 608:47/usr/bin/pg_restore92->../../usr/lib64/pgsql92/bin/pg_restore
lrwxrwxrwx1 root root38 February 608:36/usr/bin/pg_restore96->../../usr/lib64/pgsql96/bin/pg_restore
lrwxrwxrwx1 root root 27 February 608:47/usr/bin/pg_rewind->/etc/alternates/pg_rewind
lrwxrwxrwx1 root root 37 February 608:36/usr/bin/pg_rewind96->../../usr/lib64/pgsql96/bin/pg_rewind
lrwxrwxrwx1 root root 28 February 608:47/usr/bin/pg_standby->/etc/alternates/pg_standby
lrwxrwxrwx1 root root38 February 608:36/usr/bin/pg_standby96->../../usr/lib64/pgsql96/bin/pg_standby
lrwxrwxrwx1 root root 31 December 608:47/usr/bin/pg_test_fsync->/etc/alternates/pg_test_fsync
lrwxrwxrwx1 root root41 December 608:36/usr/bin/pg_test_fsync96->../../usr/lib64/pgsql96/bin/pg_test_fsync
lrwxrwxrwx1 root root32 February 608:47/usr/bin/pg_test_timing->/etc/alternates/pg_test_timing
lrwxrwxrwx1 root root42 February 608:36/usr/bin/pg_test_timing96->../../usr/lib64/pgsql96/bin/pg_test_timing
lrwxrwxrwx1 root root 29 February 608:47/usr/bin/pg_xlogdump->/etc/alternates/pg_xlogdump
lrwxrwxrwx1 root root 39 February 608:36/usr/bin/pg_xlogdump96->../../usr/lib64/pgsql96/bin/pg_xlogdump
-rwxr-xr-x1 root root 375360 October 14 2012/usr/bin/pgawk
lrwxrwxrwx1 root root25 February 608:47/usr/bin/pgbench->/etc/alternates/pgbench
lrwxrwxrwx1 root root 35 February 608:36/usr/bin/pgbench96->../../usr/lib64/pgsql96/bin/pgbench
- rwxr-xr-x2 root root 15872 March 17 2015/usr/bin/pgrep

There was no file containing libpq, so I thought this might be the cause, so I did the following, but I couldn't install it.

$sudo yum install libpq-dev
Plug-ins loaded: priorities, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00:00     
amzn-updates | 2.5kB 00:00:00     
23 packages excluded due to repository priority protection
Package libpq-dev is not available.

Does the gem install pg fail because there is no libpq-dev?
If the above is the reason, what command can I use to install it?
I would like to resolve the gem install pg error.

Thank you for your cooperation.

ruby-on-rails ruby postgresql amazon-ec2 amazon-linux

2022-09-30 17:05

3 Answers

If you installed PostgreSQL from the PostgreSQL repository, you must install the corresponding packages as well.

Install postgresql96-develop


2022-09-30 17:05

These errors are often caused by the lack of path.
Even if you want to install the same postgres, there are many different patterns from yum and source to compilation, package, homebrew, etc., and you have to specify the path to the files you need when installing the gem.
However, in this case,

Can't find the 'libpq-fe.h header

It says , but sometimes you do not pass the path directly to the file.
(for example, pg_config)

Why don't you refer to this and so on?


2022-09-30 17:05

Check to see if gcc is installed


2022-09-30 17:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.