Postgres and rvm annoyances

This is the second time that I’ve hit this issue trying to install the ‘pg’ Ruby gem on Ubuntu 12.04.

$ gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.
    /home/dspisak/.rvm/rubies/ruby-1.9.3-p362/bin/ruby extconf.rb
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 ***
...

I found workaround in a StackOverflow issue here. My steps are:

$ mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm
$ vim Gemfile   ### change the gem source protocol to http for a few minutes
$ bundle install
$ vim Gemfile   ### change the source back to https
$ mv ~/.rvm/usr/lib_rvm ~/.rvm/usr/lib

The process renames the rvm user library directory while we install pg. After successfully installing the gem, restore the Gemfile source and the user library.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.