Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active February 7, 2024 19:19
Show Gist options
  • Save fernandoaleman/ee3ac6957c2ba4f7d7d33a251d58b191 to your computer and use it in GitHub Desktop.
Save fernandoaleman/ee3ac6957c2ba4f7d7d33a251d58b191 to your computer and use it in GitHub Desktop.
Install mysql2 on MacOS Mojave

For MacOS Catalina, visit Install mysql2 on MacOS Catalina

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

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
@bparanj
Copy link

bparanj commented Feb 21, 2022

This:

bundle config build.mysql2 --srcdir=/usr/local/mysql/include
bundle install

worked for me on Monterey 12.2.1 with M1 chip

@dblanken
Copy link

Thank you @bparanj. That worked perfectly for me as well.

@DavidAmyot
Copy link

Tried all of the solutions from multiple sources/websites and the only one that worked on a M2 2023 was gem install mysql2 -v '0.3.18' -- --srcdir=/opt/homebrew/Cellar/mysql/8.0.33_2/include. Other solutions were working for more recent versions of the mysql2 gem though.

@fcastaneitron
Copy link

Tried all of the solutions from multiple sources/websites and the only one that worked on a M2 2023 was gem install mysql2 -v '0.3.18' -- --srcdir=/opt/homebrew/Cellar/mysql/8.0.33_2/include. Other solutions were working for more recent versions of the mysql2 gem though.

Awesome!!! This was the only solution that worked for me. You saved my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment