Unable to Install MySQL2 Gem on Bigsur

ld: library not found for -lzstd while bundle install for mysql2 gem Ruby on macOS Big Sur 11.4 Apple M1

Step 1:

confirm you have both openssl and MySQL installed via brew

brew install mysql

brew install openssl

or if you have previous version of openssl try

brew reinstall openssl@3

Step 2:

Run this on your Rails app to make sure you can get through bundler:

gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib

two things to note: $(brew --prefix openssl) dynamically replaces the stuff inside the evaluation $(...) to the directory of openssl on your machine.

/opt/homebrew/opt/zstd is really a symlink to the current version of zstd on your machine (which links to something like /opt/homebrew/opt/Cellar/zstd/1.5.2)

Step 3:

If you want this globally, run this:

bundle config --global build.mysql2 "--with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib"

note that this will change your ~/.bundler/config file and then applies globally to bundler

An error occurred while installing mysql2 (0.4.8), and Bundler cannot continue

I think you missing dev library of mysql:

On ubuntu

sudo apt-get install libmysqlclient-dev

On Red Hat/CentOS and other distributions using yum:

sudo yum install mysql-devel

On Mac OS X with Homebrew:

brew install mysql

Installing mysql2 gem for Ruby on Rails with Mac OSX 10.6

It seems that it cannot find the MySQL library. Have you installed MySQL?

Try installing it via homebrew:

brew install mysql

or install it via macports or fink or whatever you prefer.

Then try again with:

gem install mysql2


Related Topics



Leave a reply



Submit