Installing the PostgreSQL gem with 'gem pq' fails with ERROR: Failed to build gem native extension
Asked Answered
H

3

35

I am learning Ruby on Rails and trying to develop an application. In my application I am trying to use the default SQLite database in the Development Mode and PostgreSQL in the Production Mode. But I'm getting the following error while trying to install pg gem using: gem install pg

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.
 
    /home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev
 for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev
 for building a client-side application.
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}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
        --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 /home/tusharkhatiwada/.rvm/gems/[email protected]/g
ems/pg-0.17.0 for inspection.
Results logged to /home/tusharkhatiwada/.rvm/gems/[email protected]/gems/pg-0.17.0/ext
/gem_make.out

After that I again tried with gem install pg -- --with-pg-config= '/usr/bin/pg_config' and the following error is displayed:

Building native extensions with: '--with-pg-config= /usr/bin/pg_config'
This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.
 
    /home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb --with-pg-config= /us
r/bin/pg_config
Using config values from 
sh: 1: : Permission denied
sh: 1: : Permission denied
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}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/tusharkhatiwada/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
        --with-pg
        --without-pg
        --with-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 /home/tusharkhatiwada/.rvm/gems/[email protected]/g
ems/pg-0.17.0 for inspection.
Results logged to /home/tusharkhatiwada/.rvm/gems/[email protected]/gems/pg-0.17.0/ext
/gem_make.out
Hawsepiece answered 18/9, 2013 at 4:52 Comment(3)
Duplicate of #3116515Pronuba
@Pronuba : It didn't solve my problem either.Hawsepiece
There is some issue with your package manager. First, update your package manager by sudo apt-get update and then try to install these.Pronuba
P
125

If you are using Ubuntu try to install following lib file

sudo apt-get install libpq-dev

and then gem install pg

worked for me.

Pending answered 18/9, 2013 at 5:18 Comment(9)
I tried it but it also shows errors: You might want to run 'apt-get -f install' to correct these: The following packages have unmet dependencies:  libpq-dev : Depends: libkrb5-dev but it is not going to be installed              Depends: comerr-dev but it is not going to be installed  libssl-dev : Depends: libssl1.0.0 (= 1.0.1c-4ubuntu8.1) but 1.0.1c-4ubuntu8 is to be installed               Recommends: libssl-doc but it is not going to be installed E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).Hawsepiece
sudo apt-get update sudo apt-get install build-essential ruby-dev libpcap-devPending
This solution didn't work on my VM which was installed in cloud server at Koding but it did solve in my Laptop using Ubuntu.Hawsepiece
This worked while upgrading gitlab from 5.1 to 6.0 using the turnkey linux version.Carbolated
whenever i install postgresql i know that error will occur and i will copy-paste this command to fix this problem by google-ing.Hertford
@TusharKhatiwada - This fixed it for me in the Koding dev environment: databasically.com/2010/03/05/…Coquito
How did you realise this is what was missing?Restaurant
installing libpq-dev didnt work for me... but installing the libgmp-dev package did it.Matilda
E: Unable to correct problems, you have held broken packages.Canakin
R
0

for those who reached this by google search if libpq-dev didnt work or threw another errors i hade the same problem try upgrading your system and get the ruby div-kit

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ruby1.9.1-dev

then reboot after this just try again

...

Ray answered 25/12, 2013 at 13:19 Comment(0)
H
0

You have to do this

sudo apt-get install libgmp-dev libpq-dev

and then

gem install pg
Hertford answered 16/3, 2016 at 1:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.