can't find gem bundler (>= 0.a) with executable bundle

2,566 阅读1分钟

问题

在使用Bundler对项目依赖做管理时,使用:

bundle install

会报错:

can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

原因

Bundler2中添加了一个新特性,根据lockfile自动切换Bundler版本。这个特性在RubyGems的版本号大于2.7.0时会生效。但是会有一个bug,需要指定Bundler版本号。

解决方案

使用命令:

gem install bundler -v '1.17.3'

就可以了。

如果仍然遇到报错:

You don't have write permissions for the ...

需要获得权限,可以使用命令:

sudo gem install bundler -v '1.17.3' -n /usr/local/bin

成功之后再执行再bundle install就好了。

参考

Update the bundler command

use -n parameter to install