Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 am trying to get Ruby on Rails working on my computer but the pg gem keeps failing. I have found a lot of other questions saying that you just need to use the libpq-dev package from apt and that should fix it but it is still saying that it can't find the library.

nicholas@nick-ubuntu:~$ gem instal pg -- --with-pq-lib=/usr/lib
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /home/nicholas/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb --with-pq-lib=/usr/lib
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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:

Gem files will remain installed in /home/nicholas/.rvm/gems/ruby-1.9.3-p327/gems/pg-0.14.1 for inspection.
Results logged to /home/nicholas/.rvm/gems/ruby-1.9.3-p327/gems/pg-0.14.1/ext/gem_make.out
share|improve this question

Awhile back, I found I had to use the ruby-pg gem instead of the pg gem, which was unneeded. Also, avoid the old postgres gem.

share|improve this answer

Try installing the following packages:

postgresql and libpq-dev.

That gets the pg gem to compile the native extensions for me on 11.10, 12.04 and 12.10.

share|improve this answer

I had the same problem.

Installing postgresql and libpq-dev did the trick for me too.

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.