opensslmacos-mojavemysql2

mysql2: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib after homebrew update


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/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

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?


Solution

  • OpenSSL 1.0 reached EOL on 2019-12-31

    Reinstalling mysql2 gem with --with-cflags and --with-ldflags arguments pointing to openssl@1.1 fixed the error:

    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