Error installing pg gem -- extconf.rb failed Error installing pg gem -- extconf.rb failed postgresql postgresql

Error installing pg gem -- extconf.rb failed


I had the same problem and fixed it by:

1) $ brew update

2) $ brew install postgres

2) $ gem install pg


Just posting my own answer because the solution turned out rather unexpected, and I tried every single way to solve it I had found on Stackoverflow to no avail.

It looks like the problem was in XCode command tools that needed to be updated. I updated the command tools and then re-installed postgres with homebrew as well as reinstalled the pg gem. Worked like a charm. Works on El Capitan now also.


For me it was this answer that solved the :

Installing unf_ext 0.0.7.6 with native extensionsGem::Ext::BuildError: ERROR: Failed to build gem native extension.    current directory: /Users/luka/.rvm/gems/ruby-2.5.1/gems/unf_ext-0.0.7.6/ext/unf_ext/Users/luka/.rvm/rubies/ruby-2.5.1/bin/ruby -r ./siteconf20200122-42541-136wsjb.rbextconf.rbchecking for -lstdc++... *** extconf.rb failed ***Could not create Makefile due to some reason, probably lack of necessarylibraries and/or headers.  Check the mkmf.log file for more details.  You mayneed configuration options.