Library not loaded: /usr/local/lib/libpq.5.4.dylib

if you have upgraded

  • PostgreSQL with homebrew (brew update && brew upgrade),
  • macOS (eg. from Catalina to BigSur)

then simply uninstall the pg gem:

gem uninstall pg
bundle install

and the path will be corrected for you. No need to uninstall the whole PostgreSQL cluster.


I was running into this issue after switching over to the PostgresApp and removing the existing PostgreSQL version via

brew remove postgres

I ultimately solved the problem by re-installing PostgreSQL via

brew install postgres

I was able to retain the use of the PostgresApp by adding the following to my .bash_profile

export PATH="/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/bin:$PATH"

You can also try running:

brew doctor

As it alerted me to this as well as some additional errors.

This error was also affecting my ability to use the Paperclip gem as it was causing ImageMagick to fail with the same error.

(Using OS X 10.8.2)