MacOS 12.6下通过ruby-install安装Ruby 3.1.3配置失败求助
在 macOS 12.6 中使用 ruby-install 安装 Ruby 3.1.3 时配置失败的解决方案
问题重现
使用 ruby-install 在 macOS 12.6 安装 Ruby 3.1.3 时,配置阶段报错,核心提示为:
checking whether the C compiler works... no configure: error: C compiler cannot create executables
完整报错信息:
>>>Configuring ruby 3.1.3 ... checking for ruby... /usr/bin/ruby tool/config.guess already exists tool/config.sub already exists checking build system type... x86_64-apple-darwin21.6.0 checking host system type... x86_64-apple-darwin21.6.0 checking target system type... x86_64-apple-darwin21.6.0 checking for cl.exe... no checking for clang... clang checking for llvm-ar... no checking for clang++... clang++ checking for llvm-nm... no checking for llvm-objcopy... no checking for llvm-objdump... no checking for llvm-ranlib... no checking for llvm-strip... no checking for gcc... (cached) clang checking whether the C compiler works... no configure: error: in `/Users/jay/src/ruby-3.1.3': configure: error: C compiler cannot create executables See `config.log' for more details !!! Configuration of ruby 3.1.3 failed!
已尝试更换其他Ruby版本、rbenv/RVM等工具,问题未解决。
解决步骤
1. 修复Xcode Command Line Tools
macOS的Clang编译器依赖Xcode命令行工具,执行以下操作:
# 重置命令行工具路径并重新安装 sudo xcode-select --reset xcode-select --install
安装完成后重启终端,再尝试安装Ruby。
2. 配置编译器环境变量
手动指定CC/CXX路径,确保指向系统自带的Clang:
export CC=/usr/bin/clang export CXX=/usr/bin/clang++ # 立即执行安装 ruby-install ruby 3.1.3
3. 定位具体错误(查看config.log)
打开报错提示的config.log文件,查看末尾的详细失败原因:
cat /Users/jay/src/ruby-3.1.3/config.log
若发现SDK路径问题,手动设置SDKROOT:
export SDKROOT=$(xcrun --show-sdk-path)
4. 清理安装缓存后重试
移除旧源码包,强制重新下载编译:
rm -rf /Users/jay/src/ruby-3.1.3 ruby-install --clean ruby 3.1.3
5. 修复目录权限
确保当前用户对源码目录有读写权限:
chown -R $(whoami) /Users/jay/src/
内容的提问来源于stack exchange,提问作者pandya96
相关产品推荐
相关产品推荐

