You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M2芯片Mac执行bundle install等命令报错:cannot load such file

解决M2 Mac上Bundler加载错误问题

在M2芯片Mac上执行bundle install或RCT_NEW_ARCH_ENABLED=1 bundle exec pod install时出现如下错误:

/opt/homebrew/opt/ruby/bin/bundle:25:in load': cannot load such file -- /opt/homebrew/Cellar/ruby/3.3.3/lib/ruby/gems/3.3.0/gems/bundler-2.5.15/exe/bundle (LoadError) from /opt/homebrew/opt/ruby/bin/bundle:25:in

'

已尝试重新安装gem但问题未解决,环境信息如下:

环境信息

  • Ruby版本:ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin23]
  • Ruby路径:/opt/homebrew/opt/ruby/bin/ruby
  • Gem路径:/opt/homebrew/opt/ruby/bin/gem
  • 本地Bundler版本:
gem list bundler 

*** LOCAL GEMS ***

bundler (default: 2.5.15)
  • .zprofile配置:
eval "$(/opt/homebrew/bin/brew shellenv)"

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
exportPATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

if [ -d "/opt/homebrew/opt/ruby/bin" ]; then
  export PATH=/opt/homebrew/opt/ruby/bin:$PATH
  export PATH=`gem environment gemdir`/bin:$PATH
fi

解决方案

1. 确认Bundler实际安装路径

执行命令查看bundler的真实位置:

gem which bundler

对比输出路径与错误提示中的路径,若不一致,说明系统调用的bundle脚本指向了不存在的文件。

2. 强制重装对应版本Bundler

执行命令覆盖安装2.5.15版本的Bundler,确保文件完整:

gem install bundler -v 2.5.15 --force

3. 修复bundle脚本软链接

检查Homebrew的bundle脚本是否为无效软链接:

ls -l /opt/homebrew/opt/ruby/bin/bundle

若链接目标不存在,重新生成软链接:

ln -sf "$(gem environment gemdir)/bin/bundle" /opt/homebrew/opt/ruby/bin/bundle

4. 验证环境变量配置

先获取gem的bin目录路径:

echo $(gem environment gemdir)/bin

将该路径替换到.zprofile的PATH配置行,确保它位于最前端,然后重新加载配置:

source ~/.zprofile

5. 测试修复结果

执行bundle --version,若输出Bundler version 2.5.15,再尝试执行原命令验证问题是否解决。

内容的提问来源于stack exchange,提问作者IncognitoUser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 04:13:14