Can't install mysql2 gem on macOS Sierra Can't install mysql2 gem on macOS Sierra ruby ruby

Can't install mysql2 gem on macOS Sierra


I just had the same problem, tried all of the solutions listed above, then commenced to bang my head against they keyboard for a couple of hours.

I then thought to try and install/reinstall the Xcode Command Line Tools:

xcode-select --install

Once I did that the mysql2 gem installed w/ no problems. I hope that does the trick!


When you install openssl via brew, you should get the following message:

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your own software and it requires this formula, you'll need to add to your build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

You can set these build flags (for the local application) by running the following:

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

This worked for me.

See bundler's documentation for more information.


Lots of great answers, I was able to combine them into this:

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

because I was not comfortable with bundle config