【问题标题】:Fix Your Ruby version is 2.6.8, but your gemfile specified 2.5.5修复 你的 Ruby 版本是 2.6.8,但是你的 gemfile 指定了 2.5.5
【发布时间】:2022-12-21 14:54:24
【问题描述】:

在我的本地机器上,我使用的是rbenv

当我运行bundle install时,我得到:

The git source `git://github.com/sinatra/sinatra.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
Warning: the running version of Bundler (1.17.2) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Following files may not be writable, so sudo is needed:
  /Library/Ruby/Gems/2.6.0
  /Library/Ruby/Gems/2.6.0/build_info
  /Library/Ruby/Gems/2.6.0/cache
  /Library/Ruby/Gems/2.6.0/doc
  /Library/Ruby/Gems/2.6.0/extensions
  /Library/Ruby/Gems/2.6.0/gems
  /Library/Ruby/Gems/2.6.0/specifications
Your Ruby version is 2.6.8, but your Gemfile specified 2.5.5

问题是,当我运行 rbenv 版本时,我得到了正确的版本 (2.5.5):

  system
* 2.5.5 (set by /Users/Mahmoud/dev-reps/non-docker/normal/.ruby-version)

当我运行which ruby时,它正确地指向了 rbenv:

/Users/Mahmoud/.rbenv/shims/ruby

甚至 ruby -v 也给出了正确的版本:

ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin21]

所以大概,2.5.5 是我拥有的唯一版本。 除此之外,我尝试了所有与捆绑器相关的常用技巧:

bundle uninstall, gem uninstall bundler -v 1.17.2 但似乎没有任何效果。

我认为另一个“有趣”的事实给出了提示which bundle 给出:

/usr/local/bin/bundle

我的问题是这个 2.6.8 来自哪里?我该如何解决这个问题并启动服务器?

【问题讨论】:

  • 您的项目工作区中是否有版本文件?
  • 如果这就是您所说的,我有一个 VERSION.json 文件
  • 这可能与您的宝石集有关。 rbenv gemset list 给你什么?另外,我可以推荐使用 rvm 而不是 rbenv,如果使用 rvm 会简单得多,我只需切换 rvm use 2.5.5 就可以解决问题,但等效的 rbenv 解决方案是 rbenv local 2.5.5 我相信,也许您正在使用项目 gemset 但我不要 rbenv 如何处理那些

标签: ruby-on-rails ruby bundle bundler rbenv


【解决方案1】:

终于让它工作了。

所以问题的关键以及解决方案是which bundle给出的事实:

/usr/local/bin/bundle

which ruby​​ 给了:

/Users/Mahmoud/.rbenv/shims/ruby

表示该捆绑包未使用 rbenv 中的 ruby​​。

我已经在~/.bash_profile中设置了路径:

export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"

但显然这还不够,因为我使用的是 zsh。还必须将相同的两行添加到 ~/.zshrc 并重新启动终端。现在 bundle install 正在按预期工作。

更新~/.zshrcwhich bundle后给出:

/Users/Mahmoud/.rbenv/shims/bundle

表明问题只是那个包使用了错误的红宝石。

因此,如果您遇到此问题,只需通过添加上面指示的 2 行来确保 ~/.bash_profile~/.zshrc 具有正确的路径。重新启动终端并检查它现在是否工作。

【讨论】:

    【解决方案2】:

    苹果电脑

    使用 asdf 切换 Ruby 版本

    asdf shell Ruby 3.1.0(任何版本)

    使用 chruby 切换 Ruby 版本

    chRuby 3.1.0(任何版本)

    使用 rbenv 切换 Ruby 版本

    rbenv shell 3.0.0(任何版本)

    使用 rvm 切换 Ruby 版本

    rvm 使用 3.0.0(任何版本)

    其他信息https://mac.install.guide/faq/downgrade-ruby/index.html

    【讨论】:

      猜你喜欢
      • 2022-11-17
      • 2023-01-17
      • 1970-01-01
      • 2022-11-08
      • 2013-10-20
      • 1970-01-01
      • 2016-03-04
      • 2014-05-27
      相关资源
      最近更新 更多