MacBook Pro M2系统升级后mysql2 0.5.5安装失败求助
解决MacBook Pro M2系统升级后mysql2 gem安装失败问题
我使用MacBook Pro M2设备,原本正常运行的Ruby项目在系统升级后出现故障,执行bundle install时无法安装mysql2 (0.5.5) gem,报错信息如下:
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
已尝试的操作
- 执行
brew install mysql openssl@3 readline zlib libyaml ncurses libffi gdbm - 执行
brew install zstd - 在shell配置文件(.bash_profile、.zshrc等)中添加以下环境变量:
export PATH="/opt/homebrew/bin:$PATH" export LDFLAGS="-L$(brew --prefix)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix zstd)/lib" export CPPFLAGS="-I$(brew --prefix)/include -I$(brew --prefix openssl)/include -I$(brew --prefix zstd)/include" export PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix zstd)/lib/pkgconfig" - 重新安装Ruby 3.2.2:
rvm install 3.2.2
注意:该问题仅出现在此Mac设备,3台Ubuntu机器和另一台Mac设备无此问题。
解决方案
方案1:升级mysql2 gem到兼容版本
mysql2 0.5.5版本与MySQL 8.3+存在兼容性问题,0.5.6及以上版本已修复该问题。修改Gemfile:
gem 'mysql2', '>= 0.5.6'
执行以下命令更新并安装:
bundle update mysql2 bundle install
方案2:降级MySQL到8.2.x版本
若不想升级mysql2 gem,可降级MySQL到8.2.x版本:
brew uninstall mysql brew install mysql@8.2 brew link mysql@8.2 --force
重启终端后,执行bundle install。
方案3:手动编译mysql2 gem并忽略警告
如果上述方案无效,可手动指定编译参数安装mysql2 0.5.5:
gem install mysql2 -v 0.5.5 -- --with-mysql-config=$(brew --prefix mysql)/bin/mysql-config --with-cflags="-Wno-implicit-function-declaration"
完成后执行bundle install。
内容的提问来源于stack exchange,提问作者Hazem Hagrass
相关产品推荐
相关产品推荐

