Mac OS X下执行bundle install不使用rbenv指定的Ruby版本问题求助
问题原因
当前shell的PATH优先级中,系统Ruby的可执行文件路径排在rbenv shims路径之前,调用bundle时优先加载了系统预安装的bundler,因此实际调用的是系统Ruby 2.6.3版本。
解决方案
- 第一步:执行以下命令查看所有bundler的加载优先级,确认系统bundler是否优先于rbenv shims下的bundler加载:
which -a bundle
如果输出结果中/usr/bin/bundle排在~/.rbenv/shims/bundle之前,说明PATH优先级配置异常。
- 第二步:执行以下命令强制使用rbenv指定Ruby版本对应的bundler运行安装,可直接绕过优先级问题:
rbenv exec bundle install
- 第三步(可选,彻底修复):
- 卸载系统路径下的所有bundler版本:
sudo gem uninstall bundler -a -x- 重新为当前rbenv Ruby版本安装对应bundler:
gem install bundler -v 1.17.3- 重新生成rbenv shims,重启终端后即可正常使用
bundle install命令:
rbenv rehash
如果上述操作后仍有问题,可检查shell配置文件(/.zshrc、/.bash_profile等),确保eval "$(rbenv init -)"配置行位于所有PATH变量修改代码的最后一行,保证rbenv shims路径的优先级最高。
内容的提问来源于stack exchange,提问作者Nick Charney Kaye
相关产品推荐
相关产品推荐

