3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

macOSをアップデートしたらRailsアプリのpostgresqlが Library not loaded: /usr/local/opt/postgresql/lib/libpq.5.dylib となった話

Posted at

macOSのCatalinaからVenturaにアップデートしたら、全部のプロジェクトではないのですが、一部のRailsアプリをローカルで動かせなくなりました。

エラー内容はこちらです。

$ rails db:create       
rails aborted!
LoadError: dlopen(/Users/<ユーザー名>/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pg-1.1.4/lib/pg_ext.bundle, 0x0009): Library not loaded: /usr/local/opt/postgresql/lib/libpq.5.dylib
  Referenced from: <BBF0820F-B9B8-31CF-BC14-4B622DDC2077> /Users/<ユーザー名>/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pg-1.1.4/lib/pg_ext.bundle
  Reason: tried: '/usr/local/opt/postgresql/lib/libpq.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file, not in dyld cache) - /Users/<ユーザー名>/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pg-1.1.4/lib/pg_ext.bundle
/Users/<ユーザー名>/dev/stock-bancho/config/application.rb:7:in `<main>'
/Users/<ユーザー名>/dev/stock-bancho/Rakefile:4:in `<main>'
/Users/<ユーザー名>/dev/stock-bancho/bin/rails:9:in `<top (required)>'
/Users/<ユーザー名>/dev/stock-bancho/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
(See full trace by running task with --trace)

LoadError: dlopen(/Users/<ユーザー名>/.anyenv/envs/rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pg-1.1.4/lib/pg_ext.bundle, 0x0009): Library not loaded: /usr/local/opt/postgresql/lib/libpq.5.dylib
ここがメッセージぽいので読み解きたい。

dlopenというのは動的に読み込むファイルを開くよっていう意味らしい。

dlopenコマンドで開こうとしていたpg_ext.bundleは、gempgの拡張機能の一種らしい。
RubyからPostgreSQLデータベースにアクセスするために必要なものなのだとか。pg_ext.bundleのビルドにはlibpq.5.dylibファイルが必要で、これを開こうと思って/usr/local/opt/postgresql/lib/libpq.5.dylibを見に行ったらなかったから怒ってたのでしょう。macでディレクトリを確認してみると、確かに/usr/local/opt/postgresql/というディレクトリがありませんでした。

macOSがアップデートされて、ディレクトリ構造が変わったのかな?
パスを正しくしてあげる必要がありそうです。

結論としては、以下の通り、一度pgのgemをアンインストールして、bundle installし直したら戻りました。

gem uninstall pg

bundle install

こちらが参考になりました。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?