修复你的 Ruby 版本是 2.6.8,但是你的 gemfile 指定了 2.5.5

问题描述 投票:0回答:3

在我的本地机器上,我正在使用

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 是从哪里来的?我该如何解决这个问题并启动服务器?

ruby-on-rails ruby bundle bundler rbenv
3个回答
22
投票

终于开始工作了。

所以问题的关键以及解决方案是

which bundle
给出的事实:

/usr/local/bin/bundle

而红宝石给了:

/Users/Mahmoud/.rbenv/shims/ruby

表明捆绑包没有使用 rbenv 中的 ruby。

我已经在

~/.bash_profile
中设置了路径:

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

但显然这还不够,因为我正在使用 zsh。还必须将相同的 2 行添加到

~/.zshrc
并重新启动终端。现在 bundle install 正在按预期工作。

更新后

~/.zshrc
which bundle
给出:

/Users/Mahmoud/.rbenv/shims/bundle

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

所以如果你有这个问题,只要确保

~/.bash_profile
~/.zshrc
有正确的路径通过添加上面指示的 2 行。重新启动终端并检查它现在是否工作。


2
投票

Mac

使用 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


1
投票

我遇到了问题

“修复你的 Ruby 版本是 2.6.8,但你的 gemfile 指定为 2.7.6”

所以我遵循了以下步骤

  1. brew 安装 [email protected]
© www.soinside.com 2019 - 2024. All rights reserved.