If you are using Ruby on Rails, chances are you had to install mysql2 gem at some point of time. With some luck, this lovely error will show up:

Error installing mysql2: ERROR: Failed to build gem native extension.

It's a tricky error because the solutions that you'll find in the web will depend on the version of your OS. In my case, I'm using macOS Catalina and this is the command that works for me:

# install openssl using brew, if you haven't
$ brew install openssl

# install mysql2
$ gem install mysql2 -v '0.5.3' -- --with-mysql-config=$(brew --prefix mysql@5.7)/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

Watch out if you want to bundle mysql2 because you'll need to use different command. So, instead of doing gem install ... like above, do this instead:

$ bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl)

Once completed, your bundle install should go well.

Till next!