I\'m setting up my development environment in the new macOS Sierra .
First of all, I installed Rbenv, Ruby (2.3.1)
Almost the same scenario as @Caio Tarifa, Ruby 2.3.3, mysql 5.6 and mysql2. Tried on couple of solutions above and finally make it work with @kylekeesling's approach.
First, tried on solution 1 by @spickermann:
brew reinstall openssl && brew link openssl --force
Nothing happened, same error shown.
Second, tried on solution by @Alessandro Berardi:
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
This got different but more errors since it overwrite gem extension's config so all gem extension installation failed.
Finally, tried on @kylekeesling solution:
xcode-select --install
It fix mysql gem issue as well as nikogiri. Since I already intall Xcode, in my case it's reinstall the Xcode Command Line Tools.
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.
So I tried everything here to no avail. Seems like a problem with ruby 2.6.0, I downgraded to 2.3.4p301 and everything worked fine (with bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include")
Here's what worked for me.
Originally I ran:
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"
then
$ bundle install
I received an error in /Users/.../.bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/mysql2-0.5.3/mkmf.log :
clang: error: unsupported option '--with-cppflags=-I/usr/local/opt/openssl/include'
So I removed "--with-cppflags=-I/usr/local/opt/openssl/include"
Then ran:
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
followed by:
$ bundle install
Which worked.
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
With Mac OS 10.15 Catalina when I tried Alessandro's fix the gem and extensions could be installed correctly but bundle install failed. What worked was just:
bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"
without the cppflags part.