replace 0.3.21 with required version gem install mysql2 -v '0.3.21' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
https://stackoverflow.com/a/39628463/3034747 Hava a good feedback but doesn't work on my machine.