Reputation: 4953
After I upgraded mac OS Mojave from v10.14.0
to v10.14.2
and all the packages installed with Homebrew I started getting the following error when I run 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/[email protected]/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
I tried to uninstall mysql2
gem and install it with cpp and ld flags:
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
But it didn't help.
Also I tried to upgrade mysql2
to the latest version (v0.5.3
at the time of writing this post), but it didn't work either
ls -l /usr/local/opt/openssl/lib
gives me:
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
I do not see libssl.1.0.0.dylib
there mysql2
complains about
Have you met this error before? Were you able to fix it and how?
Upvotes: 7
Views: 9031
Reputation: 1783
I had a similar issue on my Intel Mac Monterey, installing mysql2
v 0.5.5
with ruby-3.2.2
brew install [email protected]
brew info [email protected]
Brew info would give a bunch of information. copy the openssl lib path from the above output, similar to below snippet.
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
Now install the mysql2
gem with the lib path from above. example
gem install mysql2 -v 0.5.5 -- --with-openssl-lib="/usr/local/opt/[email protected]/lib"
Upvotes: 2
Reputation: 554
I simple solution of updating brew works for me
brew update && brew upgrade
I also installed MacPorts following this instruction here
Upvotes: 0
Reputation: 1
My solution was very similar to @Hirurg103, except the --with-cflag didn't work for me:
gem install mysql2 -v 0.4.10 -- --with-ldflags=\"-L/usr/local/opt/[email protected]/lib\"
Upvotes: 0
Reputation: 1932
For anyone using rbenv
:
brew uninstall openssl
brew install rbenv/tap/[email protected]
gem uninstall mysql2
gem install mysql2 -- --with-opt-dir="$(brew --prefix rbenv/tap/[email protected])"
Upvotes: 3
Reputation: 4953
OpenSSL 1.0 reached EOL on 2019-12-31
Reinstalling mysql2
gem with --with-cflags
and --with-ldflags
arguments pointing to [email protected]
fixed the error:
gem uninstall mysql2
gem install mysql2 -v 0.4.4 -- --with-cflags=\"-I/usr/local/opt/[email protected]/include\" --with-ldflags=\"-L/usr/local/opt/[email protected]/lib\"
bundle install
Upvotes: 13
Reputation: 125
The solution for me ultimately was:
brew update
brew upgrade
Prior to trying these commands, I also had tried brew reinstall openssl
several times. I also exported LIBRARY_PATH: export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
AND I reinstalled ruby via rbenv.
So, if the brew update and upgrade doesn't clear the error for you, perhaps try reinstalling openssl. Then if that doesn't work, reinstall ruby.
Upvotes: 5