Mac M1环境下使用RVM安装Ruby任意版本均报错求助
解决Mac M1上RVM安装Ruby失败的问题
针对你遇到的__rvm_make -j8编译报错,按以下步骤排查修复:
1. 确保Xcode命令行工具完整配置
- 安装或重置Xcode命令行工具:
xcode-select --install sudo xcode-select --reset - 同意Xcode许可协议:
sudo xcodebuild -license accept
2. 安装编译Ruby必需的依赖
通过Homebrew安装openssl、readline等核心依赖:
brew install openssl@1.1 readline libyaml gmp
3. 配置环境变量,让RVM使用Homebrew依赖
根据你使用的shell(zsh或bash),编辑对应的配置文件(~/.zshrc或~/.bash_profile),添加以下内容:
# OpenSSL 1.1 配置 export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH" export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib" export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include" export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig" # Readline 配置 export PATH="/opt/homebrew/opt/readline/bin:$PATH" export LDFLAGS="-L/opt/homebrew/opt/readline/lib" export CPPFLAGS="-I/opt/homebrew/opt/readline/include" # Libyaml 配置 export PATH="/opt/homebrew/opt/libyaml/bin:$PATH" export LDFLAGS="-L/opt/homebrew/opt/libyaml/lib" export CPPFLAGS="-I/opt/homebrew/opt/libyaml/include"
执行以下命令让配置生效:
source ~/.zshrc # 若用bash则替换为 source ~/.bash_profile
4. 指定依赖路径安装Ruby
以安装3.0.2为例,执行以下命令:
# 先清理之前的编译缓存 rvm cleanup all # 移除已安装的损坏版本(如果有) rvm remove 3.0.2 # 指定依赖路径安装 rvm install 3.0.2 --with-openssl-dir=$(brew --prefix openssl@1.1) --with-readline-dir=$(brew --prefix readline) --with-libyaml-dir=$(brew --prefix libyaml)
5. 针对架构问题的额外处理
如果仍报错,尝试指定arm64架构编译:
rvm install 3.0.2 --arch arm64 --with-openssl-dir=$(brew --prefix openssl@1.1)
关于rbenv的bootsnap兼容问题
若后续仍想尝试rbenv,可更新bootsnap到最新版本,同时确保安装Ruby时指定arm64架构:
# 安装Ruby时指定架构 RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1) --enable-shared --arch arm64" rbenv install 3.0.2 # 更新bootsnap bundle update bootsnap
内容的提问来源于stack exchange,提问作者HMAD
相关产品推荐
相关产品推荐

