Mac M1环境下使用rvm安装Ruby 3.x版本报错求助
Mac M1上通过RVM安装Ruby(3.0.0/3.1.x等版本)失败:C编译器无法生成可执行文件
在Mac M1设备上尝试用rvm将Ruby版本从2.6.10p210升级到3.1.3,同时尝试安装3.0.0、3.1.0、3.1.2等版本均失败。执行rvm install 3.0.0时,系统提示无对应二进制包,转为源码编译,在configure阶段报错,日志显示**"C compiler cannot create executables"**。
控制台执行代码
alvarobarrazaramos@MacBook-Pro-de-Alvaro src % rvm install 3.0.0 ruby-3.0.0 - #removing src/ruby-3.0.0 - please wait Searching for binary rubies, this might take some time. No binary rubies available for: osx/13.0/arm64/ruby-3.0.0. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for osx. Certificates bundle '/opt/homebrew/etc/openssl@1.1/cert.pem' is already up to date. Requirements installation successful. Installing Ruby from source to: /Users/alvarobarrazaramos/.rvm/rubies/ruby-3.0.0, this may take a while depending on your cpu(s)... ruby-3.0.0 - #downloading ruby-3.0.0, this may take a while depending on your connection... ruby-3.0.0 - #extracting ruby-3.0.0 to /Users/alvarobarrazaramos/.rvm/src/ruby-3.0.0 - please wait ruby-3.0.0 - #configuring - please wait Error running 'env CFLAGS=-O3 -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/openssl@1.1/include LDFLAGS=-L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/openssl@1.1/lib ./configure --prefix=/Users/alvarobarrazaramos/.rvm/rubies/ruby-3.0.0 --disable-install-doc --enable-shared', please read /Users/alvarobarrazaramos/.rvm/log/1676851424_ruby-3.0.0/configure.log There has been an error while running configure. Halting the installation. alvarobarrazaramos@MacBook-Pro-de-Alvaro src %
日志信息
alvarobarrazaramos@MacBook-Pro-de-Alvaro src % cat /Users/alvarobarrazaramos/.rvm/log/1676851424_ruby-3.0.0/configure.log checking for ruby... /usr/bin/ruby tool/config.guess already exists tool/config.sub already exists checking build system type... aarch64-apple-darwin22.1.0 checking host system type... aarch64-apple-darwin22.1.0 checking target system type... aarch64-apple-darwin22.1.0 checking for ld... ld checking for gcc-ar... no checking for g++... g++ checking for gcc-nm... no checking for gcc-ranlib... no checking for gcc... gcc checking whether the C compiler works... no configure: error: in `/Users/alvarobarrazaramos/.rvm/src/ruby-3.0.0': configure: error: C compiler cannot create executables See `config.log' for more details alvarobarrazaramos@MacBook-Pro-de-Alvaro src %
排查与解决步骤
- 检查Xcode Command Line Tools完整性
执行xcode-select --install,若提示已安装,执行sudo xcode-select --reset重置,重启终端后重试安装。 - 验证gcc可用性
执行gcc --version,若命令不存在或无有效输出,需确保Xcode Command Line Tools已正确安装,或通过Homebrew安装gcc:brew install gcc。 - 指定OpenSSL路径安装
Ruby 3.x部分版本与OpenSSL 3.0兼容性不佳,尝试指定OpenSSL 1.1路径:rvm install 3.0.0 --with-openssl-dir=/opt/homebrew/opt/openssl@1.1 - 更新并重置RVM
更新RVM到稳定版:rvm get stable,清理编译缓存:rvm cleanup all,再重新执行安装命令。 - 尝试Rosetta 2兼容模式
右键终端图标选择「使用Rosetta打开」,在该终端环境下重新执行Ruby安装命令,部分旧版本Ruby需通过Rosetta适配ARM架构。
内容的提问来源于stack exchange,提问作者Alvaro Barraza
相关产品推荐
相关产品推荐

