Install mysql2 gem on newer MacOS
1) When installing the mysql2 gem on newer macOS, there is an error:
An error occurred while installing mysql2 (0.5.6), and Bundler cannot continue.
2) 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
3) Make sure the required tools are up-to-date.
$ brew install zstd openssl
4) 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/
5) 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.
gpt-4o-2024-08-06
2025-04-24 12:33:49
To install the mysql2 gem on newer macOS versions, ensure xcode-select is installed, update necessary tools using Homebrew, and configure paths for OpenSSL and zstd. Finally, run the gem installation with specific flags. Adjust the gem version as required.
Chrome On-device AI
2025-05-25 12:07:55