Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active April 22, 2024 23:15
Show Gist options
  • Save fernandoaleman/385aad12a18fe50cf5fd1e988e76fd63 to your computer and use it in GitHub Desktop.
Save fernandoaleman/385aad12a18fe50cf5fd1e988e76fd63 to your computer and use it in GitHub Desktop.
How to install mysql2 gem on m1 Mac

Problem

Installing mysql2 gem errors on Apple silicon M1, M2 or M3 Mac running macOS Sonoma.

Solution

Make sure mysql-client, openssl and zstd are installed on Mac via Homebrew.

Replace mysql-client with whichever mysql package you are using

brew install mysql-client openssl zstd

Install mysql2 gem.

Replace 0.5.2 with whichever version you are using

 gem install mysql2 -v '0.5.2' -- --with-mysql-lib=$(brew --prefix mysql-client)/lib --with-mysql-dir=$(brew --prefix mysql-client) --with-mysql-config=$(brew --prefix mysql-client)/bin/mysql_config --with-mysql-include=$(brew --prefix mysql-client)/include --with-ldflags="-L$(brew --prefix zstd)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix zlib)/lib" --with-cppflags="-I$(brew --prefix openssl)/include -I$(brew --prefix zlib)/include"
@fernandoaleman
Copy link
Author

@llothar, @cereberaldebris, @timokleemann, @rajanverma-me I just updated this gist with the command that is working for me as of today February 08, 2024. Would any one of you mind testing it to confirm it is also working for you?

@johnivanoff
Copy link

This worked for me on Mac Sonoma 14.2.1

brew install mysql-client openssl zstd
gem install mysql2  -- --with-mysql-config=$(brew --prefix mysql)/bin/mysql_config --with-ldflags="-L$(brew --prefix zstd)/lib -L$(brew --prefix openssl)/lib" --with-cppflags=-I$(brew --prefix openssl)/include --with-cflags="-Wno-error=implicit-function-declaration"

@trevorh
Copy link

trevorh commented Feb 10, 2024

This worked for me on Mac Sonoma 14.2.1

brew install mysql-client openssl zstd
gem install mysql2  -- --with-mysql-config=$(brew --prefix mysql)/bin/mysql_config --with-ldflags="-L$(brew --prefix zstd)/lib -L$(brew --prefix openssl)/lib" --with-cppflags=-I$(brew --prefix openssl)/include --with-cflags="-Wno-error=implicit-function-declaration"

This worked perfectly, even with using rbenv. Thanks!

@caroline-medeiros
Copy link

for sonoma 14.3.1, anyone???

@fernandoaleman
Copy link
Author

@caroline-medeiros I am running this on the latest macOS Sonoma and it is working.

@caroline-medeiros
Copy link

I needed to add this cflags --with-cflags="-Wno-error=implicit-function-declaration" thanks!

@haanhduclinh
Copy link

Thanks. your solution is work. I try many before but it doesn't work

@naoyanickf
Copy link

@trevorh you are awesome

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