【问题标题】:Always the same version of gem is installing?总是安装相同版本的 gem?
【发布时间】:2021-11-06 18:58:12
【问题描述】:

我正在尝试通过以下方式创建新的ruby on rails 项目:

rails new . --no-ri --no-rdoc

但是在这个命令执行结束时我得到了:

         run  bundle install
Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    rails (= 4.2.6) was resolved to 4.2.6, which depends on
      bundler (< 2.0, >= 1.3.0)

  Current Bundler version:
    bundler (2.2.27)

Your bundle requires a different version of Bundler than the one you're running.
Install the necessary version with `gem install bundler:2.0.0.pre.3` and rerun bundler using `bundle _2.0.0.pre.3_ install`
Fetching gem metadata from https://rubygems.org/.............
Resolving dependencies...
         run  bundle exec spring binstub --all
Traceback (most recent call last):
    13: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    12: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    11: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/setup.rb:20:in `<top (required)>'
    10: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/ui/shell.rb:88:in `silence'
     9: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/ui/shell.rb:136:in `with_level'
     8: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/setup.rb:20:in `block in <top (required)>'
     7: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler.rb:149:in `setup'
     6: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/runtime.rb:18:in `setup'
     5: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/definition.rb:234:in `specs_for'
     4: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/definition.rb:483:in `materialize'
     3: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/definition.rb:262:in `resolve'
     2: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/resolver.rb:23:in `resolve'
     1: from /var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/resolver.rb:46:in `start'
/var/lib/gems/2.5.0/gems/bundler-2.2.27/lib/bundler/resolver.rb:59:in `rescue in start': Bundler could not find compatible versions for gem "bundler": (Bundler::VersionConflict)
  In Gemfile:
    rails (= 4.2.6) was resolved to 4.2.6, which depends on
      bundler (< 2.0, >= 1.3.0)

  Current Bundler version:
    bundler (2.2.27)

Your bundle requires a different version of Bundler than the one you're running.
Install the necessary version with `gem install bundler:1.11.2` and rerun bundler using `spring _1.11.2_ binstub --all`

之后我删除了 ruby​​,所以使用命令 ruby -v 我得到了:

bash: /home/iva/.rbenv/shims/ruby: No such file or directory

然后我再次安装了 ruby​​ 并使用 gem install bundler:1.11.2 安装了 gem。但是在安装了检查 ruby​​ 和 gem 的版本之后,我得到了:

ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
gem -v
2.7.6

当我使用版本1.11.2 发出命令时,我不知道这个2.7.6 版本的gem 怎么样? 所以它似乎是一个圈子,我不知道如何摆脱它。我正在安装 ruby​​,它需要旧版本的 gem,但是任何命令都会在我的计算机上安装最新版本的 gem。在这种情况下我该怎么办?

================================================ =============== 此命令的响应是:

rbenv versions
* 2.5.1 (set by /home/iva/.rbenv/version)
echo $PATH
/home/iva/.rbenv/shims:/home/iva/.rbenv/bin:/home/iva/.rbenv/shims:/home/iva/.rbenv/bin:/home/iva/.rbenv/shims:/home/iva/.rbenv/bin:/home/iva/.rbenv/shims:/home/iva/.rbenv/bin:/home/iva/.rbenv/shims:/home/iva/.rbenv/bin:/home/iva/.rbenv/shims:/home/iva/.rbenv/bin:/home/iva/bin:/home/iva/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/iva/.rvm/bin:/home/iva/.rvm/bin:/home/iva/.rvm/bin:/home/iva/.rvm/bin:/home/iva/.rvm/bin

【问题讨论】:

  • 你是如何重新安装 Ruby 的?你能发布rbenv versionsecho $PATH的输出吗?
  • 我在我的问题中添加了对rbenv versionsecho $PATH 命令的响应。我正在使用stackoverflow.com/questions/37720892/… 那里的教程重新安装 ruby​​(第三次回答 39 次:(2019 年 1 月)要使用 Rbenv 脚本安装 Ruby,请按照以下步骤操作:)

标签: ruby-on-rails ruby rubygems


【解决方案1】:
  1. 您为什么要创建一个新的 Rails 项目使用 rails 版本 4.2.6?这真的是故意的吗?! Rails 4.2.6 于 2016 年 3 月 11 日为 released。它相当老旧/过时,不再受支持。 latest version of rails6.1.4.1

  2. 错误信息说你的bundler的版本和rails的版本不兼容。该错误中没有任何内容表明您需要重新安装 ruby​​,但我想它没有造成任何伤害......

  3. gembundler 是不同的东西。要检查bundler 的版本,请运行:bundle -v,而不是gem -v。您应该希望看到1.11.2 如您所料。

简而言之:

  • 我认为您当前的设置没有任何问题。如果你重新安装rails v4.2.6,然后运行rails new,我希望它可以工作。您的困惑似乎在于比较不同事物的版本(即rubygembundler)。
  • 如果您刚刚安装了所有内容的最新版本,就可以避免这种混淆。我不清楚你为什么要尝试用这么旧的版本创建一个新的 rails 项目。也许您有充分的理由做出该决定,这很好;但如果没有,那么就使用最新版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多