How to install the mysql2 Ruby gem on a Mac M1

a_chris

Christian

Posted on May 18, 2022

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 🚀

💖 💪 🙅 🚩
a_chris
Christian

Posted on May 18, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related