Failing installing pg gem, "mkmf.rb can't find header files for ruby" (Mac OSX 10.6.5) Failing installing pg gem, "mkmf.rb can't find header files for ruby" (Mac OSX 10.6.5) postgresql postgresql

Failing installing pg gem, "mkmf.rb can't find header files for ruby" (Mac OSX 10.6.5)


I encountered this error when I tried to install rails by gem on CentOS 6.3.

After googling a bit, I found a quick fix: installing the ruby-devel package.

sudo yum install ruby-devel

After that, everything worked fine.


Generally the gem bundles for Postgres want to know where pg_config is hiding so they can ask about the Postgres installation.

Use locate pg_config to see if your Mac knows where it's hiding.

I installed a copy of Postgres using mappstack, so my Mac says there's a copy at:

/Applications/mappstack-1.2-3/postgresql/bin/pg_config

and another at:

/Library/PostgreSQL/9.0/bin/pg_config

I don't remember installing the one at /Library/PostgreSQL/9.0, so it might have been preinstalled by Snow Leopard, or I did it when under the influence of too much work, possibly using the Postgres installer from EnterpriseDB.

Once you've found the location of pg_config try adding that directory to the start of your PATH and then rerun the gem install. Or use:

export SQL_PATH=/Library/PostgreSQL/9.0gem install pg -- --with-pg-config=$SQL_PATH/bin/pg_config

and try installing. If either of those work you're done. Otherwise...

The next thing the installers might want are access to the Postgres headers, so you look in the parent of the bin directories, and see if you can find an include directory.

After that, look in that directory for a lib directory. Once you know those locations you should have all you need to set your environment variables to let the installer complete. You'll need to read the README or INSTALL file of the installer and see what needs to be set up. You'll be configuring:

export include_dir=$SQL_PATH/include/export     lib_dir=$SQL_PATH/lib/gem install pg -- --with-pgsql-include-dir=$include_dir --with-pgsql-lib-dir=$lib_dir

Hopefully that'll all help. I have Rails 3 and my Postgres running fine, using the mappstack Postgres and the EnterpriseDB versions, so the above info should get you there.


This worked for me on OS X 10.6.6, with PostgreSQL 9.0.1 installed from the source code:

export PATH=/usr/local/psql/bin:$PATHexport ARCHFLAGS='-arch x86_64'gem install pg

You'll likely need to edit that PATH to match your postgres install location.