katou02
@katou02 (Meitoku)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

rails sでLoadError: dlopen

bundle exec rails s を実行したところ

bundler: failed to load command: rails (/Users/user/.rbenv/versions/2.5.1/bin/rails)
LoadError: dlopen(/Users/user名/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /usr/local/opt/mysql@5.6/lib/libmysqlclient.18.dylib
  Reason: image not found - /Users/user名/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/lib/mysql2/mysql2.bundle

のエラーが発生してしまいます

関係あるかわかりませんが、brew install redisをやってからおかしくなったような気がします
半日は色々試しましたが解決できません
よろしくお願いいたします

試したこと

1

こちらこちらを参考にしてmysql@5.6配下にlibmysqlclient.18.dylibが無かったため作成

mysql@5.6でlsをするとlibmysqlclient.18.dylibが確認できました

COPYING             bin             lib             my.cnf              sql-bench
INSTALL_RECEIPT.json        homebrew.mxcl.mysql@5.6.plist   libexec             scripts             support-files
README              include             libmysqlclient.18.dylib     share

しかしエラーは解決せず

2

こちらを参考に

brew update && brew upgrade

を実行

Error: 
  homebrew-core is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!

解決せず

3

こちらを参考に

brew switch openssl ~~

commandのエラーが発生します

Error: Unknown command: switch

4

bundle doctorをやってもよく分からないものが出てきます

--- TEMPLATE END ----------------------------------------------------------------

Unfortunately, an unexpected error occurred, and Bundler cannot continue.

5

rubyの再インストール
解決せず

0

1Answer

Homebrew でインストールしたライブラリに動的リンクしているネイティブ拡張 gem があるとき、 brew upgradebrew cleanup でライブラリのファイルパスが変わったり削除されたりすると LoadError が起きます。 brew install でもときどき自動クリーンアップが走るはずなので、そのせいで libmysqlclient.18.dylib が消えたのでしょう。

bundle pristine を実行して gem をリビルドすれば直ると思います。それでだめなら ~/.rbenv を消すかリネームして退避するかしてから rbenv で Ruby をインストールし直してください。

なお、シンボリックリンクを作るのはいい解決策とは言えません。一時しのぎにはなりますが、次の brew upgradebrew cleanup でリンク元のファイルが消えるかも分からないからです。

1Like

Comments

  1. @katou02

    Questioner

    解決できました、ありがとうございました!

Your answer might help someone💌