mysql2 gem がバンドラーを壊しています。 mysql2 (0.5.5) のインストール中にエラーが発生しました

概要

私はMacBook Pro M2マシンを持っています。正常に動作していた Ruby プロジェクトがあり、システム アップグレードを行った後、壊れてしまいました。 プロジェクトでバンドルインストールを実行しようとしていますが、以下のエラーが発生します。

An error occurred while installing mysql2 (0.5.5), and Bundler cannot continue
Fetching gem metadata from https://rubygems.org/.......
Installing mysql2 0.5.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
/Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/bin/ruby extconf.rb --with-opt-dir\=/opt/homebrew/opt/zstd
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_gc_mark_movable()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
-----
Using --with-openssl-dir=/opt/homebrew/opt/openssl@3
-----
-----
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_DEFAULT_AUTH in mysql.h... yes
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Setting rpath to /opt/homebrew/Cellar/mysql/8.3.0_1/lib
-----
creating Makefile

current directory: /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240309-60899-3sw70c sitelibdir\=./.gem.20240309-60899-3sw70c clean

current directory: /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5/ext/mysql2
make DESTDIR\= sitearchdir\=./.gem.20240309-60899-3sw70c sitelibdir\=./.gem.20240309-60899-3sw70c
compiling client.c
In file included from client.c:15:
./mysql_enc_name_to_ruby.h:43:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb_hash (str, len)
^
./mysql_enc_name_to_ruby.h:86:1: warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x [-Wdeprecated-non-prototype]
mysql2_mysql_enc_name_to_rb (str, len)
^
client.c:1438:3: error: call to undeclared function 'mysql_ssl_set'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  mysql_ssl_set(wrapper->client,
  ^
client.c:1438:3: note: did you mean 'mysql_close'?
/opt/homebrew/Cellar/mysql/8.3.0_1/include/mysql/mysql.h:797:14: note: 'mysql_close' declared here
void STDCALL mysql_close(MYSQL *sock);
             ^
2 warnings and 1 error generated.
make: *** [client.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/gems/mysql2-0.5.5 for inspection.
Results logged to /Users/hazemhagrass/.rvm/gems/ruby-3.2.2/extensions/arm64-darwin-23/3.2.0/mysql2-0.5.5/gem_make.out

  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:125:in `run'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:51:in `block in make'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `each'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `make'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:193:in `build_extension'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:227:in `block in build_extensions'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:224:in `each'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:224:in `build_extensions'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/installer.rb:852:in `build_extensions'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/rubygems_gem_installer.rb:76:in `build_extensions'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/source/rubygems.rb:205:in `install'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/gem_installer.rb:54:in `install'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/gem_installer.rb:16:in `install_from_spec'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/parallel_installer.rb:132:in `do_install'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/installer/parallel_installer.rb:123:in `block in worker_pool'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:62:in `apply_func'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:57:in `block in process_queue'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:54:in `loop'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:54:in `process_queue'
  /Users/hazemhagrass/.rvm/rubies/ruby-3.2.2/lib/ruby/site_ruby/3.2.0/bundler/worker.rb:90:in `block (2 levels) in create_threads'

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

In Gemfile:
mysql2

それがmysql2パッケージに関連していることがわかり、解決策がないまま修正しようと多くのチュートリアルに従いました。

以前に試したことのヒントをいくつか紹介します。

注意事項: 3 台の Linux Ubuntu マシンと 2 台の Mac デバイスにアクセスできます。これは Mac でのみ発生しており、Ubuntu では発生しません。

解決策

gem ロックを削除し、次の手順を適用することで問題を解決しました。