Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I cant get the pg gem to install. I have tried --with-pg_config and it didnt 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.
share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer

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

share|improve this answer

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



share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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