---
title: Install mysql2 gem on newer MacOS
url: https://calvin.my/posts/install-mysql2-gem-on-newer-macos
published: 2025-04-24
updated: 2026-09-16
category: Development
tags:
- MacOS
- MySQL
- Ruby
- Gem
summary: The post addresses installation failures for the mysql2 gem on newer macOS versions. It recommends confirming that Apple’s command-line developer tools are installed, updating required Homebrew dependencies including compression and encryption libraries, and configuring library and header search paths. The gem installation then requires additional build options pointing to those dependencies. Readers should adjust the specified gem version to match their project’s requirements.
---

# Install mysql2 gem on newer MacOS

1. When installing the `mysql2` gem on newer macOS, there is an error:

```markup
An error occurred while installing mysql2 (0.5.6), and Bundler cannot continue.
```

2. First, make sure the xcode-select is installed.

```bash
$ 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.

```bash
$ brew install zstd openssl
```

4. Prepare the paths.

```bash
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:

```bash
$ 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.

&nbsp;
