[英]How to `bundle install` when your Gemfile requires an older version of bundler?
I am in an older Rails project that has a Gemfile.我在一个有 Gemfile 的旧 Rails 项目中。 I tried to add a gem to the Gemfile and
bundle install
but got an error:我尝试将 gem 添加到 Gemfile 并
bundle install
但出现错误:
Bundler could not find compatible versions for gem "bundler":
In Gemfile:
rails (= 3.0.0) ruby depends on
bundler (~> 1.0.0) ruby
Current Bundler version:
bundler (1.1.5)
This Gemfile requires a different version of Bundler.
The version of Rails it's using requires bundler ~>1.0.0 but I have 1.1.5 installed and am using it for my other projects.它使用的 Rails 版本需要 bundler ~>1.0.0,但我安装了 1.1.5 并将它用于我的其他项目。 Usually I would use
bundle exec ...
but since this is bundler we are talking about, it's a little more complicated than that.通常我会使用
bundle exec ...
但由于这是我们正在谈论的 bundler,所以它比那要复杂一些。 How can I add a gem to my Gemfile and run bundle install
while using the version of bundler that it requires?如何在使用它所需的捆绑程序版本时将 gem 添加到我的 Gemfile 并运行
bundle install
?
First you need to install the appropriate version of bundler:首先你需要安装合适版本的bundler:
% gem install bundler -v '~> 1.0.0'
Successfully installed bundler-1.0.22
Then force rubygems to use the version you want ( see this post ):然后强制 rubygems 使用你想要的版本( 见这篇文章):
% bundle _1.0.22_ install
The error message In Gemfile: bundler (~> 1.16)
is a bit inaccurate, since the version number requirement can come from other places, such as the .gemspec
file, which was the case for me: In Gemfile: bundler (~> 1.16)
的错误消息有点不准确,因为版本号要求可能来自其他地方,例如.gemspec
文件,我就是这种情况:
spec.add_development_dependency "bundler", "~> 1.16"
Removing the version number from the .gemspec
file solved the issue for me:从
.gemspec
文件中删除版本号为我解决了这个问题:
spec.add_development_dependency "bundler"
I had the same issue on macOS Mojave.我在 macOS Mojave 上遇到了同样的问题。 I installed the different version of the bundler gem and uninstall the current version.
我安装了不同版本的 bundler gem 并卸载了当前版本。
gem install bundler -i '2.0.1'
gem uninstall bundler
Then gives me the option to choose the version to uninstall and I choose the one which is creating the problem.然后让我选择要卸载的版本,然后我选择导致问题的版本。
This is what I had to do to get it to work to install with a previous version (2.2.11) of bundler:这是我必须做的才能让它与先前版本 (2.2.11) 的 bundler 一起安装:
gem install bundler:2.2.11
bundle _2.2.11_ install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.