install pg with native extension error

I was getting trouble to install pg gem. The error i was getting is

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

I also found some tips on SO. It was to locate the postgre’s config (pg_config) to bundler before running `bundle install` command. For general postgresql installation,

bundle config --with-pg-config=/usr/pgsql-9.1/bin/pg_config

(path was not same for me on Mac OSx. It was /Library/PostgreSQL/9.1/bin/pg_config)

But this did not solve my problem. I was still getting the same error when i was running bundler. However, when i tried to install the gem separately with this directive set, it worked fine.

gem install pg -- --with-pg-config=/Library/PostgreSQL/9.1/bin/pg_config

Now the gem is installed fine and i ran the `bundle install` and it was installed without issues.

Try it!

  • Hans Hauge

    When you say “-config=/Library/PostgreSQL/9.1/bin” is that a literal path or? Assuming you’re on Linux? I don’t have home/Library or usr/Library on Ubuntu 13.10.

    I’m having the same issue but that directory does not exist on my machine. I have usr/include/postgresql but this directory does not include a “bin” directory.

    I’m not even sure where I’m going with this, I’be been googling for several hours and I’m not making progress it seems.

    Most people say “sudo apt-get install libpq5” but that gives me “libpq5 is already the newest version.”

    Here’s my stack trace:

    Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/hansthered/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb –with-pg-config=/usr/pgsql-9.1/bin/pg_config
    Using config values from /usr/pgsql-9.1/bin/pg_config
    sh: 1: /usr/pgsql-9.1/bin/pg_config: not found
    sh: 1: /usr/pgsql-9.1/bin/pg_config: not found
    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.

    I’ve also tried uninstalling Ruby, RVM and recloning my project.

    And this:

    That last one actually says it installed, but then bundle install fails again with the same message.

  • TheHungryCoder

    Hello Hans,
    No, that path specific for Mac OSx. I’ve mentioned that in the post. I’m sorry if that wasn’t apparent enough.

    You should use your PostgreSQL path in that case.