简体   繁体   English

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

[英]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 ):然后强制 ruby​​gems 使用你想要的版本( 见这篇文章):

% 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.

相关问题 如何使用特定版本的捆绑器捆绑安装 gemfile - How to bundle install gemfile with specific version of bundler 当我使用 bundle install 时如何修复“你的 Ruby 版本是 2.3.3,但你的 Gemfile 指定了 2.7.1” - How to fix “Your Ruby version is 2.3.3, but your Gemfile specified 2.7.1” when i use bundle install 如何修复捆绑程序问题:您已经激活了 mysql 2.7,但您的 Gemfile 需要 mysql 2.8.1。 考虑使用 bundle exec - HOw to fix bundler issue: You have already activated mysql 2.7, but your Gemfile requires mysql 2.8.1. Consider using bundle exec 如何为捆绑安装指定捆绑程序的版本 - How to specify version of bundler for bundle install 为什么捆绑安装会在可用的Gemfile中不使用捆绑器的版本? - Why does bundle install not use the version of bundler in Gemfile though its available? 为什么Bundler在知道gemfile需要特定版本时更新gem - Why does bundler update gems when it knows the gemfile requires a specific version Bundler :: RubyVersionMismatch:您的Ruby版本是1.9.3,但您的Gemfile指定为2.0.0 - Bundler::RubyVersionMismatch: Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0 Bundler :: RubyVersionMismatch:您的Ruby版本是2.3.1,但是您的Gemfile指定了2.1.8 - Bundler::RubyVersionMismatch: Your Ruby version is 2.3.1, but your Gemfile specified 2.1.8 Bundler:您正在尝试在更改 Gemfile 后以部署模式安装 - Bundler: You are trying to install in deployment mode after changing your Gemfile Gemfile语法错误:尝试捆绑安装时 - Gemfile syntax error: when trying bundle install
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM