我有 MacBook Pro m2 机器。我有一个正常工作的 ruby 项目,在进行系统升级后,它坏了。 我正在尝试在我的项目中运行
bundle install
,但收到以下错误。
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 包有关,我遵循了很多教程试图修复它但没有解决方案。
以下是我之前尝试过的一些提示:
$brew install mysql openssl@3 readline zlib libyaml ncurses libffi 数据库管理
$brew 安装 zstd
设置环境变量以帮助 gem 找到必要的库:将以下行添加到 shell 配置文件(.bash_profile、.zshrc 等)中:
$ 导出 PATH="/opt/homebrew/bin:$PATH"
$ 导出 LDFLAGS="-L$(brew --prefix)/lib -L$(brew --prefix openssl)/lib -L$(brew --prefix zstd)/lib"
$ 导出 CPPFLAGS="-I$(brew --prefix)/include -I$(brew --prefix openssl)/include -I$(brew --prefix zstd)/include"
$ 导出 PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig:$(brew --prefix zstd)/lib/pkgconfig"
rvm安装3.2.2ruby
注意事项: 我可以访问 3 台 Linux Ubuntu 机器和 2 台 Mac 设备。这种情况仅发生在 Mac 上,而不是 Ubuntu 上。
我通过移除宝石锁并应用以下步骤解决了这个问题: