Ruby-on-rails 当您的 Gemfile 需要旧版本的捆绑器时,如何“捆绑安装”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12092928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:40:57  来源:igfitidea点击:

How to `bundle install` when your Gemfile requires an older version of bundler?

ruby-on-railsrubybundler

提问by Andrew

I am in an older Rails project that has a Gemfile. I tried to add a gem to the Gemfile and bundle installbut got an error:

我在一个有 Gemfile 的旧 Rails 项目中。我试图向 Gemfile 添加一个 gem,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. Usually I would use bundle exec ...but since this is bundler we are talking about, it's a little more complicated than that. How can I add a gem to my Gemfile and run bundle installwhile using the version of bundler that it requires?

它使用的 Rails 版本需要 bundler ~>1.0.0,但我安装了 1.1.5 并将它用于我的其他项目。通常我会使用,bundle exec ...但由于这是我们正在谈论的捆绑器,因此它比那要复杂一些。如何将 gem 添加到我的 Gemfile 并bundle install在使用它所需的捆绑程序版本时运行?

回答by alexsanford1

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):

然后强制 ruby​​gems 使用你想要的版本(见这篇文章):

% bundle _1.0.22_ install

回答by Asbj?rn Ulsberg

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 .gemspecfile, 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 .gemspecfile solved the issue for me:

.gemspec文件中删除版本号为我解决了这个问题:

spec.add_development_dependency "bundler"

回答by gsumk

I had the same issue on macOS Mojave. I installed the different version of the bundler gem and uninstall the current version.

我在 macOS Mojave 上遇到了同样的问题。我安装了不同版本的 bundler gem 并卸载了当前版本。

gem install bundler -i '2.0.1'

gem install bundler -i '2.0.1'

gem uninstall bundler

gem uninstall bundler

Then gives me the option to choose the version to uninstall and I choose the one which is creating the problem.

然后让我选择要卸载的版本,然后我选择导致问题的版本。