For MacOS Catalina, visit Install mysql2 on MacOS Catalina
Installing mysql2 gem errors on MacOS Mojave.
Make sure openssl is installed on Mac via Homebrew.
brew install openssl
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
This is the key line in the error:
Note the extra backslashes; it's escaping the string in the bundle config so it's passed to
extconf.rbas a single parameter, which is silently ignored.In my case it was also enough to only specify the lib dir. I'm guessing the
--with-opt-dirin the newer comments is a way to set both with a single option in cases where the include dir also needs to be set. It would be better if bundle had a way to specify multiple parameters.I did this with
bundle config --local build.mysql2 --with-ldflags=-L/usr/local/opt/openssl/lib, including--localso it would be saved in the repo so future developers don't have to hunt this down like I did, but we'll see if that breaks our CICD.