15
2

【Rails】bundle install時のmysql2エラーの解消方法

Last updated at Posted at 2024-03-14

概要

ローカルの Ruby on Rails で bundle install を実行したときに、mysql2のインストールで以下のエラーが出てしまうことがあります。

Installing mysql2 0.5.6 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

# (略)

Gem files will remain installed in
/Users/watasho/study/batch_sample/.bundle/ruby/3.2.0/gems/mysql2-0.5.6 for inspection.
Results logged to
/Users/watasho/study/batch_sample/.bundle/ruby/3.2.0/extensions/arm64-darwin-22/3.2.0/mysql2-0.5.6/gem_make.out

# (略)

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

In Gemfile:
  mysql2

本記事では、その場合の対処法についてまとめています。

結論

brewのmysqlのバージョンを8.3から8.0に下げることで解決。

解決方法

筆者の環境では、brewでmysqlをインストールしていたのですが、8.3がインストールされていました。

$ brew list | grep mysql

mysql-client@8.3
mysql@8.3

バージョン8.3の、上記mysqlクライアントとmysqlサーバーをアンインストールし、バージョン8.0の同様のものをインストールすることで、bundle install時にmysql2のインストールができるようになりました。

最近起きた問題のようです。

$ brew uninstall mysql-client@8.3
$ brew uninstall mysql@8.3

$ brew install mysql-client@8.0
$ brew install mysql@8.0

参考サイト

15
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
2