在我将mac OS Mojave从v10.14.0
升级到v10.14.2
以及使用Homebrew安装的所有软件包后,当我运行bin/rails console
时,我开始收到以下错误:
/Users/hirurg103/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': dlopen(/Users/hirurg103/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.4/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /usr/local/opt/mysql@5.6/lib/libmysqlclient.18.dylib
Reason: image not found - /Users/hirurg103/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.4/lib/mysql2/mysql2.bundle
我尝试卸载mysql2
gem 并使用 cpp 和 ld 标志安装它:
gem uninstall mysql2
gem install mysql2 -v 0.4.4 -- --with-cppflags=-I/usr/local/opt/openssl/include/openssl --with-ldflags=-L/usr/local/opt/openssl/lib
但这并没有帮助。
我也试图mysql2
升级到最新版本(在撰写本文时v0.5.3
(,但它也没有用
ls -l /usr/local/opt/openssl/lib
给了我:
total 14472
drwxr-xr-x 4 hirurg103 staff 128 Sep 10 16:13 engines-1.1
-r--r--r-- 1 hirurg103 staff 2265596 Dec 13 19:06 libcrypto.1.1.dylib
-r--r--r-- 1 hirurg103 staff 3930864 Sep 10 16:13 libcrypto.a
lrwxr-xr-x 1 hirurg103 staff 19 Sep 10 16:13 libcrypto.dylib -> libcrypto.1.1.dylib
-r--r--r-- 1 hirurg103 staff 485860 Dec 13 19:06 libssl.1.1.dylib
-r--r--r-- 1 hirurg103 staff 720400 Sep 10 16:13 libssl.a
lrwxr-xr-x 1 hirurg103 staff 16 Sep 10 16:13 libssl.dylib -> libssl.1.1.dylib
drwxr-xr-x 5 hirurg103 staff 160 Dec 13 19:06 pkgconfig
我没有看到libssl.1.0.0.dylib
mysql2
抱怨
您以前遇到过此错误吗? 您是否能够修复它以及如何修复它?
OpenSSL 1.0 于 2019-12-31 达到 EOL
重新安装带有指向openssl@1.1
--with-cflags
和--with-ldflags
参数mysql2
gem 修复了错误:
gem uninstall mysql2
gem install mysql2 -v 0.4.4 -- --with-cflags="-I/usr/local/opt/openssl@1.1/include" --with-ldflags="-L/usr/local/opt/openssl@1.1/lib"
bundle install
我的最终解决方案是:
brew update
brew upgrade
在尝试这些命令之前,我也尝试了几次brew reinstall openssl
。我还导出了LIBRARY_PATH:export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
,我通过 rbenv 重新安装了 ruby。
因此,如果brew更新和升级没有为您清除错误,请尝试重新安装openssl。然后,如果这不起作用,请重新安装 ruby。
对于任何使用rbenv
的人:
brew uninstall openssl
brew install rbenv/tap/openssl@1.0
gem uninstall mysql2
gem install mysql2 -- --with-opt-dir="$(brew --prefix rbenv/tap/openssl@1.0)"
我的解决方案与@Hirurg103非常相似,除了 --with-cflag 对我不起作用:
gem install mysql2 -v 0.4.10 -- --with-ldflags="-L/usr/local/opt/openssl@1.1/lib"
我更新brew的简单解决方案对我有用
brew update && brew upgrade
我还按照此处的说明安装了MacPorts。