Cannot install mysql2 gem for Rails project Cannot install mysql2 gem for Rails project ruby-on-rails ruby-on-rails

Cannot install mysql2 gem for Rails project


From the answer at this question, running the following worked for me

gem install mysql2 --source 'https://rubygems.org/' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include


I ran into this same issue on Mojave, and none of the previous answers worked for me but this commands mentioned in this Github issue comment did

Step 1.

brew install openssl

Step 2.

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

In my case I already had openssl installed so it was really the export command that solved the problem.


  1. Make sure openssl is installed on Mac via Homebrew.
brew install openssl
  1. Install mysql2 gem.
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
  1. If the bug is not fixed, this above solution is the last one
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Another solution if the above does not work.

cd /usr/local/Cellar/openssl/1.0.2s/lib/sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib