[Ruby FAQs - mysql2] gem install mysql2

gem install mysql2

ld: library not found for -lssl

There may encountered the following error when installing the mysql2 gem on macOS:

1
2
3
4
5
6
7
$ gem install mysql2 # or bundle
...
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
...
    1. Make sure openssl is installed on Mac via Homebrew.
1
$ brew install openssl
    1. Install mysql2 gem.
1
$ gem install mysql2 -v '0.5.3' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

See Cannot install mysql2 gem for Rails project - Stack Overflow - https://stackoverflow.com/questions/43523389/cannot-install-mysql2-gem-for-rails-project to learn more.

References

[1] Cannot install mysql2 gem for Rails project - Stack Overflow - https://stackoverflow.com/questions/43523389/cannot-install-mysql2-gem-for-rails-project

[2] mysql2 | RubyGems.org | your community gem host - https://rubygems.org/gems/mysql2/

[3] RubyGems.org | your community gem host - https://rubygems.org/

[4] MySQL - https://www.mysql.com/

[5] /source/index.html - https://www.openssl.org/

[6] [[email protected] — Homebrew Formulae - https://formulae.brew.sh/formula/[email protected]]

[7] The Missing Package Manager for macOS (or Linux) — Homebrew - https://brew.sh/