Error requiring pg under rvm with postgres.app Error requiring pg under rvm with postgres.app postgresql postgresql

Error requiring pg under rvm with postgres.app


Edit: Even though this answer currently has more votes than the accepted answer, the accepted answer is far simpler and cleaner.


Remove the Postgres.app binaries from the path when installing the pg gem, and instead use the postgres install built into OS X to configure the gem. The pg library will still correctly connect to the Postgres.app server later on.

Rammy:~ phrogz$ gem uninstall pgSuccessfully uninstalled pg-0.15.1# Modify PATH to remove /Applications/Postgres.app/Contents/MacOS/binRammy:~ phrogz$ gem install pgFetching: pg-0.15.1.gem (100%)Building native extensions.  This could take a while...Successfully installed pg-0.15.11 gem installedRammy:~ phrogz$ ruby -v -e "require 'pg'"ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]


I found a solution that works for me and requires minimal hacking/configuring. You only need to do this once and it will work for every bundle install. Add the following to your .bash_profile, .bash_rc, or equivalent:

export DYLD_FALLBACK_LIBRARY_PATH=/Applications/Postgres.app/Contents/MacOS/lib:$DYLD_LIBRARY_PATH

(Assuming you installed Postgres.app in the default location). Then restart your terminal session and try again.

Exporting to DYLD_LIBRARY_PATH directly can cause serious problems with other apps that depend on it, but using the fallback path avoids these problems.

See also:

EDIT: It seems that setting DYLD_FALLBACK_LIBRARY_PATH causes an error when you try to run psql. To fix this, you can add the following two lines to your .bash_profile:

alias psql="(. ~/.bash_profile; unset DYLD_FALLBACK_LIBRARY_PATH; psql)";

This is assuming that you're using bash and that your .bash_profile is located in your home directory. If that's not the case (or if you're using a .bashrc or other environment setup instead of .bash_profile) change the ~/.bash_profile part of the command to the path to your environment setup script.

The aliased commands basically start a subshell which does not effect your current bash environment. So when it unsets the DYLD_FALLBACK_LIBRARY_PATH variable, it's only temporary. After you exit psql the environment variable will be set again so that rails functions properly.


This worked for me:

sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

Just double check that the /Applications/Postgres93.app.. path exists for you.