Postgres gem native extension error

I hit this error when installing the pg gem for using postgresql with rails apps.

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

        /Users/userx/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
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.

Provided configuration options:
	--with-opt-dir
	--without-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=/Users/kengimel/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
	--with-pg
	--without-pg
	--with-pg-dir
	--without-pg-dir
	--with-pg-include
	--without-pg-include=${pg-dir}/include

I already have postgres installed, so what? it appears postgres does not know when to find the its native extension files.

To solve you need to locate bin directory for your postgresql in the Library directory. Depending the version of postgres you are running, the path to the bin folder may differ.

including the below to you .bashrc or .bash_profile or .profile or .zshrc will do the trick :)


PATH=${PATH}:/Library/PostgreSQL/9.1/bin
source .zshrc
gem install pg

For centos users this post could be of help.
and/or
Prepend with a variable assignment for PATH with the location of the pg_config file, for example:


export PATH=/usr/pgsql-9.1/bin:$PATH
source .bashrc
gem install pg

Check that postgres is running:

service postgresql-9.1 status

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s