I can't get the pg gem to install. I have tried --with-pg_config and it didn't work.

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
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.

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

If you haven't done it already, install and initialize apt-file. This tool tells you what package contains a file with the given name.

sudo apt-get install apt-file
apt-file update

Then run apt-file search libpq-fe.h to find out what package contains this file, and install the package in question. (It's libpq-dev.)

You can also search for this file name in some package installation GUIs, or online.


The problem is likely due to missing postgresql development package. You can either install it manually or use the package manager from your distribution. Probably packages missing (install them with apt-get install):

  1. libpq-dev
  2. postgresql-server-dev-all

You can also try to install the ruby pg extension from your repository via apt-get install libpgsql-ruby


What worked for me was doing the following:

sudo apt-get install postgresql
sudo apt-get install libpq-dev


bundle gem install pg


bundle install





First of all i want you to apt-get installpostgresql

then apt-get install libpgsql-ruby

then apt-get install libpq-dev

then do apt-get install postgresql-server-dev-all

and finally gem install pg -v 0.19.0

IF you are trying to install metasploit then be sure to run this too after you have finishid the above

rvm use 2.3
bundle install

let us know if this worked for you ? We care abaut your problems, also if you ever need something else feel free to ask

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.