Search code examples
ruby-on-railspostgresqlosx-maverickspg

Installing pg gem; ERROR: Failed to build gem native extension


After updating to OS X 10.9 Mavericks I tried to start a Rails 3 app, but the connection to the PG database was not working. Checking on PGAdmin III, the database is still there and it works fine. So I tried to reinstall the pg gem:

gem uninstall pg
gem install pg

But the last command doesn't succeed, and gives the following error:

Building native extensions. This could take a while... ERROR: Error installing pg:

ERROR: Failed to build gem native extension.

    /Users/XXX/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb checking for pg_config... yes Using config values from

/usr/local/bin/pg_config * 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.

/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file.

(RuntimeError) You have to install development tools first. from /Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:461:in try_link0' from /Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:476:in try_link' from extconf.rb:39:in `'

I guess the problem is related to the Xcode developer tools. I updated Xcode to the latest version, but that didn't solve the problem. Do you know how to fix it?


Solution

  • Using homebrew fixed this for me:

    gem uninstall pg
    brew install apple-gcc42
    gem install pg
    

    EDIT: I also manually installed "devtools"

    xcode-select --install