Installing mysql2 Gem on Mac with Apple Silicon
Installing mysql2 Gem on Mac with Apple Silicon
Introduction
Recently, I’m helping an old friend to upgrade their old Rails 4.2.8 + Ruby 2 project to Rail 5 and Ruby 3. Because it just cant run on new machinese anymore.
The biggest trouble I faced doing this was getting all these dependency gems getting installed and making the project run on my new Apple Silicon Mac (M4 Air to be precise). Well since the project is too old, it cant really run on any new machine anymore. Some gems don’t even exist anymore.
At some point i was stuck on installing mysql2
gem. Which alwasy failed on building native extensions.
After googling lots and trying quite a few from github issues and stack overflow. This github issue answer actually helped. https://github.com/brianmario/mysql2/issues/1346#issuecomment-1920076974
So what i did was:
- Install mysql with homebrew
brew install mysql
2 Install libraries needed
brew install mysql-connector-c
- Now manually install
mysql2
, instead of using bundle install:
gem install mysql2 -- --with-mysql-dir="/opt/homebrew/opt/mysql-client"
- now back to
bundile install
, it should just work.
A bit sad to see my projects are being too old that things are not supported anymore….. time does go fly….my friends.