3

I've been (unsuccessfully) trying to install the "pg" gem on my ruby 1.9.3-p286 but nothing seems to work.

I've already installed postgresql (9.1), libpq-dev and a few others like postgresql-server-dev-9.1. I've tried to pass the "with-pg-config" flag to the gem install but simply nothing seems to work.

Every time I try to install the gem it outputs something like this:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /home/lynux/.rvm/rubies/ruby-1.9.3-p286/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 ***
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
    --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/lynux/.rvm/rubies/ruby-1.9.3-p286/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pqlib
    --without-pqlib
    --with-libpqlib
    --without-libpqlib
    --with-ms/libpqlib
    --without-ms/libpqlib


Gem files will remain installed in /home/lynux/.rvm/gems/ruby-1.9.3-p286@phisiodata/gems/pg-0.14.1 for inspection.
Results logged to /home/lynux/.rvm/gems/ruby-1.9.3-p286@phisiodata/gems/pg-0.14.1/ext/gem_make.out

What am I doing wrong? Is there something else that I should do before trying to install the gem?

Thank you in advance.

[EDIT]

Ok, so joelparkerhenderson's answer set me to think that there might me something wrong with paths and libraries and a went on digging a little bit further..

I've found this awesome post and it solved! Basically the problem lies with RVM. So, my problem is solved and for anyone out there that might suffer from the same thing, follow the link!

Community
  • 1
  • 1
Lynx_Eyes
  • 311
  • 1
  • 7

1 Answers1

2

Your error looks like you're missing libpq-dev

Are you about to install Postgres first on the system?

Try this:

sudo apt-get install postgresql postgresql-client postgresql-server-dev-all libpq-dev

Next, are you able to install the pg gem as root?

sudo su - root
gem install pg
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • Hi Joel. Thanks for the quick answer. I've only had time to look at this today, but it didn't work :( It still complaints telling it can't find the Postgresql client library :| I've tried to do what you told on another machine with a 32bit version of ubuntu and all went ok, could it have something to do with it? – Lynx_Eyes Dec 04 '12 at 22:37