DEV Community

Christian
Christian

Posted on

How to install the mysql2 Ruby gem on a Mac M1

The Mac M1 family has been presented more than two year ago and I still encounter a new issue every time I try to install the mysql2 Ruby gem.
But... I think I've finally found a set of commands to fix all these issues!

First of all, install the required dependencies:

brew install gcc zstd openssl mysql
Enter fullscreen mode Exit fullscreen mode

now export all the libraries paths which we need to build the gem:

export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
export LIBRARY_PATH=$LIBRARY_PATH:$(brew --prefix zstd)/lib/
Enter fullscreen mode Exit fullscreen mode

aaaand now install the mysql gem:

gem install mysql2 -v '0.5.4' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L$(brew --prefix zstd)
Enter fullscreen mode Exit fullscreen mode

woila', I'm 100% this will succed, if don't please leave a comment so we can figure out a new solution to help who will read this post 🚀

Top comments (4)

Collapse
 
megatux profile image
Cristian Molina

Thanks! still works w/v0.5.5

Collapse
 
buithehien1991 profile image
Bùi Thế Hiển

Thank you so much!

Collapse
 
imazdren profile image
Azdren

Thanks for sharing this solution.

Collapse
 
siyanda profile image
Maphumulo

Thank you !