4
1

More than 1 year has passed since last update.

An error occurred while installing mysql2 (0.5.3), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'` succeeds before bundling.

Last updated at Posted at 2021-07-23

誰もが1回はぶち当たったことであろう問題

rails new 〜 -d mysql でアプリ作って、bundle install したら発生するこのエラー。
もういい加減呆れ果てたので解決方法をまとめます。

環境

MacBook Air (M1, 2020)
Ruby 3.0.2
Rails 6.1.4

解決方法

先に結論から。
こちらのコマンドを実行後、bundle install したら成功します。(2022/02/02修正)

terminal
- bundle config --local build.mysql2 "--with-ldflags=-L/opt/homebrew/lib --with-opt-dir=/opt/homebrew/opt/openssl"
+ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

ここからは原因調査(執筆中。。。)

まずはエラーメッセージを振り返ろう。

terminal
〜〜〜 前略 〜〜〜

2 warnings generated.
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1

make failed, exit code 2

〜〜〜 後略 〜〜〜

この中の ld: library not found for -lzstd に注目。
日本語に直訳すると zstdのためのライブラリが見つからへん となりますね🤔

〜〜〜 以降追記予定(2021.07.23 現在) 〜〜〜

参考記事

4
1
0

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
4
1