The key part of the error is:
Library not loaded: libpq.5.dylib (LoadError)
This suggests that ruby can't find libpq
at runtime. To address that you should probably set the DYLD_LIBRARY_PATH
environment variable to point to the lib
directory of your PostgreSQL install, either globally or in a wrapper script you use to start Rails. See this superuser question for some more info.
The Pg
gem can find the library during compilation and installation because the pg_config
executable is on the PATH
and it uses that to find libpq
. It appears that it doesn't store the path for use at runtime so you have to set the runtime dynamic linker up yourself.
A simple wrapper script (in case you don't want to modify your global environment) is something like:
#!/bin/bash
export DYLD_LIBRARY_PATH=/path/to/pg/lib
exec rails "$@"
The "$@" basically means "pass all arguments to this script through as if they were passed here directly". It preserves quoting correctly and essentially means that the rails command can't tell you didn't run it directly.