Sonoma 14.3.1系统下mysql2 gem安装失败求助
解决Sonoma 14.3.1下安装mysql2 gem时的libressl路径错误问题
问题背景
在Sonoma 14.3.1系统中,已通过brew安装MySQL 8.3.0_1、OpenSSL 3.3.0、zstd 1.5.6,且安装了Xcode 15.3.0。执行以下命令安装mysql2 gem时:
gem install mysql2 -- --with-mysql-lib=/usr/local/Cellar/mysql/8.3.0_1/lib --with-mysql-dir=/usr/local/Cellar/mysql/8.3.0_1 --with-mysql-config=/usr/local/Cellar/mysql/8.3.0_1/bin/mysql_config --with-mysql-include=/usr/local/Cellar/mysql/8.3.0_1/include
出现以下错误:
checking for rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes checking for rb_gc_mark_movable()... no checking for rb_wait_for_single_fd()... yes checking for rb_enc_interned_str() in ruby.h... no ----- Cannot find library dir(s) /AppleInternal/Library/BuildRoots/4e1473ee-9f66-11ee-8daf-cedaeb4cabe2/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.3.Internal.sdk/usr/local/libressl-by-deployment-target/13.0/lib ----- *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers.
错误原因是编译mysql2时,错误尝试引用Xcode内部的libressl路径,而非brew安装的OpenSSL。
解决方案
1. 修改gem安装命令,指定brew的OpenSSL路径
在原安装命令中添加OpenSSL相关参数,强制使用brew安装的OpenSSL:
gem install mysql2 -- \ --with-mysql-lib=/usr/local/Cellar/mysql/8.3.0_1/lib \ --with-mysql-dir=/usr/local/Cellar/mysql/8.3.0_1 \ --with-mysql-config=/usr/local/Cellar/mysql/8.3.0_1/bin/mysql_config \ --with-mysql-include=/usr/local/Cellar/mysql/8.3.0_1/include \ --with-openssl-dir=$(brew --prefix openssl)
如果上述命令无效,可以直接指定OpenSSL的具体路径:
gem install mysql2 -- \ --with-mysql-lib=/usr/local/Cellar/mysql/8.3.0_1/lib \ --with-mysql-dir=/usr/local/Cellar/mysql/8.3.0_1 \ --with-mysql-config=/usr/local/Cellar/mysql/8.3.0_1/bin/mysql_config \ --with-mysql-include=/usr/local/Cellar/mysql/8.3.0_1/include \ --with-openssl-lib=/usr/local/Cellar/openssl@3/3.3.0/lib \ --with-openssl-include=/usr/local/Cellar/openssl@3/3.3.0/include
2. 确保Xcode命令行工具配置正确
重置Xcode命令行工具路径,避免引用内部SDK:
sudo xcode-select --reset
验证路径是否正确:
xcode-select -p
正确输出应为/Applications/Xcode.app/Contents/Developer,若不一致,手动指定:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
3. 清理编译缓存后重试
清理之前的mysql2编译缓存,避免残留问题:
gem cleanup mysql2 rm -rf ~/.gem/ruby/*/gems/mysql2-*
之后重新执行修改后的gem安装命令。
4. 检查MySQL与OpenSSL的兼容性
确认brew安装的MySQL依赖的OpenSSL版本是否匹配当前安装的版本:
brew info mysql
查看输出中的依赖项,若存在版本不兼容,可重新安装对应版本的OpenSSL或MySQL。
内容的提问来源于stack exchange,提问作者Ruslan Lukichev
相关产品推荐
相关产品推荐

