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/ruby-2.0.0-p247@rails4.0.0/g
ems/pg-0.17.0 for inspection.
Results logged to /home/tusharkhatiwada/.rvm/gems/ruby-2.0.0-p247@rails4.0.0/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/ruby-2.0.0-p247@rails4.0.0/g
ems/pg-0.17.0 for inspection.
Results logged to /home/tusharkhatiwada/.rvm/gems/ruby-2.0.0-p247@rails4.0.0/gems/pg-0.17.0/ext
/gem_make.out
unom
  • 11,438
  • 4
  • 34
  • 54
Tushar Khatiwada
  • 2,019
  • 2
  • 20
  • 32

3 Answers3

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.

arulmr
  • 8,620
  • 9
  • 54
  • 69
santosh
  • 1,611
  • 1
  • 13
  • 21
  • 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).` – Tushar Khatiwada Sep 18 '13 at 06:04
  • sudo apt-get update sudo apt-get install build-essential ruby-dev libpcap-dev – santosh Sep 19 '13 at 08:55
  • This solution didn't work on my VM which was installed in cloud server at [Koding](http://koding.com) but it did solve in my Laptop using Ubuntu. – Tushar Khatiwada Sep 22 '13 at 03:37
  • This worked while upgrading gitlab from 5.1 to 6.0 using the turnkey linux version. – Matt Slagle Nov 21 '13 at 21:34
  • whenever i install postgresql i know that error will occur and i will copy-paste this command to fix this problem by google-ing. – Paritosh Piplewar Dec 21 '13 at 21:23
  • @TusharKhatiwada - This fixed it for me in the Koding dev environment: http://www.databasically.com/2010/03/05/installing-sqlite-headers-on-ubuntu-sqlite3-h-not-found/ – Craig Treptow Jan 07 '14 at 19:00
  • How did you realise this is what was missing? – Jim Jan 21 '14 at 00:02
  • installing libpq-dev didnt work for me... but installing the libgmp-dev package did it. – François Feb 15 '16 at 14:18
  • E: Unable to correct problems, you have held broken packages. – Ckt22 Dec 28 '21 at 13:33
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

...

Haytham Mtair
  • 107
  • 2
  • 4
  • 13
0

You have to do this

sudo apt-get install libgmp-dev libpq-dev

and then

gem install pg
Paritosh Piplewar
  • 7,982
  • 5
  • 26
  • 41