Unable to install pg gem: Could not create Makefile due to some reason

Hi All,
While installing postgres gem, getting following error-

#===== ERROR MESSAGE START ===========

Building native extensions. This could take a while…

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/ext/builder.rb:54: warning: Insecure world writable dir /usr/local in PATH, mode 040777

ERROR: Error installing pg:

ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb

checking for pg_config… yes

Using config values from /usr/local/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 /Users/apple/.rvm/gems/ruby-2.1.2@learning/gems/pg-0.17.1 for inspection.

Results logged to /Users/apple/.rvm/gems/ruby-2.1.2@learning/gems/pg-0.17.1/ext/gem_make.out

#===== ERROR MESSAGE END ===========

Googled a lot, but could not found any working solution. Could anyone please suggest what should be the resolution?

Here is my gem environment-

#=========== GEM ENVIRONMENT START ==================

RubyGems Environment:


  • RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [universal.x86_64-darwin13]

  • INSTALLATION DIRECTORY: /Users/apple/.rvm/gems/ruby-2.1.2@learning

  • RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby

  • EXECUTABLE DIRECTORY: /Users/apple/.rvm/gems/ruby-2.1.2@learning/bin


  • ruby

  • universal-darwin-13


  • /Users/apple/.rvm/gems/ruby-2.1.2@learning

  • /Users/apple/.rvm/gems/ruby-2.1.2@global


  • :update_sources => true

  • :verbose => true

  • :backtrace => false

  • :bulk_threshold => 1000


  • https://rubygems.org/

#=========== GEM ENVIRONMENT END ==================

I am using OS X 10.9.4

I appreciate any help…


Himanshu Prakash

Make sure libpq-dev package is installed.

Thanks for you reply.

Following has helped me-

Use brew to get postgresql

brew install postgresql

Check you have pg_config in the installed brew. I found mine in


Check via :

$ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config


Once done, install the pg gem with

Ref- https://stackoverflow.com/questions/19625487/impossible-to-install-pg-gem-on-my-mac-with-mavericks/22259364#22259364?newreg=657757c5d48a4b6994d4868568d94c4b