-
When installing the
mysql2gem on newer macOS, there is an error:An error occurred while installing mysql2 (0.5.6), and Bundler cannot continue. -
First, make sure the xcode-select is installed.
$ xcode-select --install xcode-select: note: Command line tools are already installed. Use "Software Update" in System Settings or the softwareupdate command line interface to install updates -
Make sure the required tools are up-to-date.
$ brew install zstd openssl -
Prepare the paths.
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/ -
Install the gem with 2 additional settings, like below:
$ gem install mysql2 -v '0.5.6' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L$(brew --prefix zstd)Adjust the version number as needed.
Advertisements
AI Summary
gpt-5.6-terra
2026-09-17 00:06:17
The post addresses installation failures for the MySQL Ruby driver gem on newer macOS versions. It recommends confirming that Apple’s command-line developer tools are installed, updating required package dependencies through Homebrew, configuring compiler and library search paths for OpenSSL and compression libraries, and passing additional build options during gem installation. Readers should adapt the package version to their project’s requirements.
Chrome On-device AI