Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am working on a rails app.
Installed Postgresql using postgresql-9.1.2-1-osx.dmg
Installed pg gem.
Then when I executed rake db:create getting the following error -

dlopen(/Users/sathishvc/.rvm/gems/ruby-1.9.3-head@knome-vivacious/gems/pg-0.12.2/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/lib/libpq.5.4.dylib

Checked if /usr/local/lib/libpq.5.4.dylib exists or not. It does not.
So, it should be existing somewhere else in the system or I do not know, if I need to install any other piece of software for this.

Advice anyone please?

like image 973
Sathish Avatar asked Jan 26 '12 18:01

Sathish


5 Answers

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.

like image 184
awenkhh Avatar answered Nov 16 '22 11:11

awenkhh


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)

like image 31
Eric Norcross Avatar answered Sep 23 '22 23:09

Eric Norcross


I'm on OSX Monterey (M2-chipset) and had a similar issue. Running (mind the version) helped:

sudo ln -s /opt/homebrew/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /usr/local/lib/libpq.5.dylib

brew update, brew link --force, brew uninstall && brew install,.. all did not.

like image 96
S.D. Avatar answered Nov 16 '22 10:11

S.D.


For me (MacOS Monterey) the file eventually turned up under: /usr/local/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib

So to fix the initial error first create the directory it is looking for and then create a symlink to the existing file:

sudo mkdir -p /usr/local/opt/postgresql/lib/
sudo ln -s /usr/local/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /usr/local/opt/postgresql/lib/libpq.5.dylib
like image 20
Sebastian Hätälä Avatar answered Nov 16 '22 09:11

Sebastian Hätälä


Try to run

bundle pristine pg

and that was it. you find solution here: https://github.com/Homebrew/homebrew-core/issues/109644

like image 20
ryan jeff Avatar answered Nov 16 '22 10:11

ryan jeff