7

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?

Hirurg103
  • 4,783
  • 2
  • 34
  • 50

5 Answers5

13

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
Hirurg103
  • 4,783
  • 2
  • 34
  • 50
  • better to update new version since old version doest work. `gem install mysql2 -v 0.4.10 -- --with-cflags=\"-I/usr/local/opt/openssl@1.1/include\" --with-ldflags=\"-L/usr/local/opt/openssl@1.1/lib\"` what I did remove version completely `gem install mysql2 -- --with-cflags=\"-I/usr/local/opt/openssl@1.1/include\" --with-ldflags=\"-L/usr/local/opt/openssl@1.1/lib\"` – isaman kumara Nov 01 '20 at 07:39
5

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.

Capella
  • 115
  • 1
  • 9
3

For anyone using 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)"

Matthew Hinea
  • 1,872
  • 19
  • 31
0

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/openssl@1.1/lib\"
0

I simple solution of updating brew works for me

  brew update && brew upgrade

I also installed MacPorts following this instruction here

pensebien
  • 506
  • 4
  • 16