简体   繁体   English

修复rbenv和rails 5.2的“您的Ruby版本为2.4.4,但您的Gemfile指定了2.5.1”的错误

[英]Fixing 'Your Ruby version is 2.4.4, but your Gemfile specified 2.5.1' error with rbenv and rails 5.2

I know there are many many questions about this with various ruby versions. 我知道有很多关于红宝石版本的问题。 I believe I have exhausted all of the normal fixes (which usually work). 我相信我已经用尽了所有正常的修复方法(通常可以使用)。

This is an application that has been working, in the same environment that I have now for several months (and years before that for other people). 这是一个已经在与我现在已经有几个月(在其他人之前已经有几年)的环境中工作的应用程序。 It has previously worked with both ruby 2.4.4 and ruby 2.5.1 (switching with rbenv). 以前它可以同时使用ruby 2.4.4和ruby 2.5.1(使用rbenv切换)。

I want ruby 2.5.1 and bundler is complaining that my ruby version is 2.4.4 我想要ruby 2.5.1,并且bundler抱怨我的ruby版本是2.4.4

$ bundle exec rspec
Your Ruby version is 2.4.4, but your Gemfile specified 2.5.1

$ rbenv exec bundle exec rspec
Your Ruby version is 2.4.4, but your Gemfile specified 2.5.1

NOTE: rspec is the example but it is happening for any command prepended with bundle exec 注意: rspec是示例,但bundle exec任何命令都在发生

I have checked all the places that I know about, and all the places that the internet has suggested I should look, and cannot find what is setting ruby to 2.4.4 (see details below). 我检查了我所知道的所有地方,以及互联网建议我应该看的所有地方,并且找不到将ruby设置为2.4.4的原因(请参阅下面的详细信息)。

So the real question is - where is the next place to look for a mis-configured file for either rbenv or bundler or both? 因此,真正的问题是-在哪里寻找rbenvbundler或两者的配置错误的文件?

All of these things give me the correct ruby version 所有这些东西给了我正确的红宝石版本

The basics: 基础:

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

$ which ruby
/home/vagrant/.rbenv/shims/ruby

$ rbenv which ruby
/home/vagrant/.rbenv/versions/2.5.1/bin/ruby

$ bundle -v
Bundler version 1.16.3

$ which bundle
/home/vagrant/.rbenv/shims/bundle

$ rbenv which bundle
/home/vagrant/.rbenv/versions/2.5.1/bin/bundle

$ bundle platform --ruby
ruby 2.5.1p57

$ rbenv version
2.5.1 (set by /path/to/app/.ruby-version)

$ rbenv local
2.5.1

$ rbenv global
2.5.1

$ head Gemfile -n 6
source 'https://rubygems.org'
git_source(:github) { |name| "https://github.com/#{name}.git" }

ruby '2.5.1'

gem 'rails', '~> 5.2.0'

$ tail Gemfile.lock -n 5
RUBY VERSION
   ruby 2.5.1p57

BUNDLED WITH
   1.16.3

bundle env 捆绑环境

$ bundle env

## Environment

```
Bundler       1.16.3
  Platforms   ruby, x86_64-linux
Ruby          2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
  Full Path   /home/vagrant/.rbenv/versions/2.5.1/bin/ruby
  Config Dir  /home/vagrant/.rbenv/versions/2.5.1/etc
RubyGems      2.7.6
  Gem Home    /home/vagrant/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
  Gem Path    /home/vagrant/.gem/ruby/2.5.0:/home/vagrant/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
  User Path   /home/vagrant/.gem/ruby/2.5.0
  Bin Dir     /home/vagrant/.rbenv/versions/2.5.1/bin
Tools
  Git         1.9.1
  RVM         not installed
  rbenv       rbenv 1.1.1-37-g1c772d5

  chruby      not installed
```

## Bundler Build Metadata

```
Built At          2018-07-17
Git SHA           12e73cab7
Released Version  true
```

... (snip)

RUBY VERSION
   ruby 2.5.1p57

BUNDLED WITH
   1.16.3

gem env 宝石环境

RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/vagrant/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /home/vagrant/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /home/vagrant/.rbenv/versions/2.5.1/bin/ruby
  - EXECUTABLE DIRECTORY: /home/vagrant/.rbenv/versions/2.5.1/bin
  - SPEC CACHE DIRECTORY: /home/vagrant/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/vagrant/.rbenv/versions/2.5.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/vagrant/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
     - /home/vagrant/.gem/ruby/2.5.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/vagrant/.rbenv/versions/2.5.1/bin
     - /home/vagrant/.rbenv/libexec
     - /home/vagrant/.rbenv/plugins/ruby-build/bin
     - /home/vagrant/.rbenv/shims
     - /home/vagrant/.rbenv/shims
     - /home/vagrant/.rbenv/shims
     - /home/vagrant/.rbenv/bin
     - /home/vagrant/.rbenv/shims
     - /home/vagrant/.rbenv/bin

cat

$ cat /home/vagrant/.rbenv/versions/2.5.1/bin/bundler
#!/home/vagrant/.rbenv/versions/2.5.1/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0.a"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
    version = $1
    ARGV.shift
  end
end

if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('bundler', 'bundler', version)
else
gem "bundler", version
load Gem.bin_path("bundler", "bundler", version)
end

Are you executing the command ruby -v from inside the project dir? 您是从项目目录中执行命令ruby -v吗? Also if you installed a new Ruby version, you should update your bundler as well. 另外,如果您安装了新的Ruby版本,则还应该更新捆绑程序。 gem install bundler or gem update bundler will do this for you. gem install bundlergem update bundler将为您完成此操作。

A bit late to the game, but perhaps this will prove helpful to somebody: 游戏有点晚了,但这也许对某些人有帮助:

TLDR; TLDR; you may have a conflicting version manager. 您可能有冲突的版本管理器。

More background information: 更多背景信息:

I use thoughtbot's laptop script to manage the software I install on my computer. 我使用Thoughtbot的笔记本电脑脚本来管理我在计算机上安装的软件。 I hadn't updated in quite a long. 我已经很长时间没有更新了。 I finally updated, but found after the update that my applications were no longer working. 我终于更新了,但是在更新后发现我的应用程序不再起作用。 After quite a bit of time spent following the usual suggestions for this issue I finally paid more attention to the actual errors I was receiving and noticed a reference to asdf . 在花了很多时间遵循这个问题的通常建议之后,我终于更加注意了我收到的实际错误,并注意到了对asdf的引用。 It turns out asdf is a general language version manager, and the scripts had started using it some time ago. 事实证明, asdf是通用语言版本管理器,并且脚本已在一段时间前开始使用它。 I had never heard of it before that. 在那之前我从未听说过。 I read a bit of the documentation, it sounded pretty good, so I removed rbenv , did the basic setup, and voila, my applications are working again! 我读了一些文档,听起来还不错,所以我删除了rbenv ,进行了基本设置,瞧,我的应用程序又可以正常工作了! This is probably also relevant if one has other ruby version managers. 如果一个人有其他的ruby版本管理器,这可能也很重要。

The long story short, having multiple version managers is probably a bad idea, which could result in all kinds of problems running applications. 长话短说,拥有多个版本管理器可能不是一个好主意,这可能会导致运行应用程序时出现各种问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您的Ruby版本是2.5.1,但您的Gemfile指定了2.6.3 - Your Ruby version is 2.5.1, but your Gemfile specified 2.6.3 您的Ruby版本是2.5.1,但您的Gemfile指定了2.4.0 - Your Ruby version is 2.5.1 but your Gemfile specified 2.4.0 您的 Ruby 版本是 2.3.1,但您的 Gemfile 指定了 2.5.1 - Your Ruby version is 2.3.1 but your Gemfile specified 2.5.1 rbenv您的Ruby版本是2.0.0,但您的Gemfile指定为2.1.2 - rbenv Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2 Mavericks,RBENV,您的 Ruby 版本是 2.0.0,但您的 Gemfile 指定的是 2.1.1 - Mavericks, RBENV, Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1 Rails服务器错误:Ruby版本是1.8.7,但您的Gemfile指定为1.9.3 - Rails Server Error: Ruby version is 1.8.7, but your Gemfile specified 1.9.3 如何解决“您的 Ruby 版本是 2.5.3,但您的 Gemfile 指定 2.5.1”部署 AWS eb? - How to fix "Your Ruby version is 2.5.3, but your Gemfile specified 2.5.1" deploying the AWS eb? rbenv您的Ruby版本是2.0.0,但是您的Gemfile指定了2.1.2,但是唯一安装的版本是2.1.2 - rbenv Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2 but the only version installed is 2.1.2 使用RVM在ruby 2.2.0上安装rails 4.2生成“你的Ruby版本是2.2.0,但你的Gemfile指定为2.1.5” - installing rails 4.2 on ruby 2.2.0 using RVM generates “Your Ruby version is 2.2.0, but your Gemfile specified 2.1.5” “您的Ruby版本是2.1.3,但是您的Gemfile指定了2.1.1”,即使我使用了rails new这样的简单命令,我也会收到此错误 - “Your Ruby version is 2.1.3, but your Gemfile specified 2.1.1” I receive this error even I use simple command like rails new
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM