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

6

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

Leitman answered 13/12, 2019 at 17:13 Comment(0)
L
13

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
Leitman answered 10/2, 2020 at 11:5 Comment(1)
better to update new version since old version doest work. gem install mysql2 -v 0.4.10 -- --with-cflags=\"-I/usr/local/opt/[email protected]/include\" --with-ldflags=\"-L/usr/local/opt/[email protected]/lib\" what I did remove version completely gem install mysql2 -- --with-cflags=\"-I/usr/local/opt/[email protected]/include\" --with-ldflags=\"-L/usr/local/opt/[email protected]/lib\"Beggarly
F
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.

Feudist answered 16/12, 2019 at 14:25 Comment(1)
I ran brew upgrade, then to fix the issue I reinstalled using gem uninstall mysql2; bundle installBarghest
M
3

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])"

Montez answered 28/9, 2020 at 19:46 Comment(2)
Caution! This is only what you want if you are installing Ruby version 2.3 or older. See: github.com/rbenv/homebrew-tapIsador
This worked for me on Ruby 2.5. Thank you.Asis
D
2

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" 
Demimonde answered 11/11, 2023 at 7:29 Comment(1)
This one worked for me. Same issue on mysql2 0.5.5 with Ruby 3.Freddiefreddy
M
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/[email protected]/lib\"
Melly answered 26/10, 2020 at 9:15 Comment(0)
R
0

I simple solution of updating brew works for me

  brew update && brew upgrade

I also installed MacPorts following this instruction here

Ryan answered 13/5, 2021 at 12:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.