如何修复“您的 Ruby 版本为 1.9.3,但您的 Gemfile 指定为 2.0.0”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19342044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 22:51:23  来源:igfitidea点击:

How to fix "Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0"

ruby-on-railsruby

提问by theone1one

I created a Ruby project, but when running bundle updateand bundle installit returns an error:

我创建了一个Ruby项目,但在运行时bundle update,并bundle install返回一个错误:

Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

An image of it is: http://i.imgur.com/dZMhI11.png?1

它的图像是:http: //i.imgur.com/dZMhI11.png?1

My gemfile is:

我的宝石文件是:

ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.0'

group :development do
    gem 'sqlite3', '1.3.8'
end

gem 'sass-rails', '4.0.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.0'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
    gem 'sdoc', '0.3.20', require: false
end

采纳答案by Jeremy Green

If you run ruby -vyou're going to see that you've installed Ruby 1.9.3, but the first line in your Gemfile specifies that you want to use Ruby 2.0.0.

如果您运行,ruby -v您将看到您已经安装了 Ruby 1.9.3,但是 Gemfile 中的第一行指定您要使用 Ruby 2.0.0。

You should either install Ruby 2.0.0 or change the first line in your Gemfile to specify Ruby 1.9.3.

您应该安装 Ruby 2.0.0 或更改 Gemfile 中的第一行以指定 Ruby 1.9.3。

sample of Gemfile:

Gemfile 示例:

source 'https://rubygems.org'
ruby "1.9.3"

gem 'pry'

gem 'pry-nav'

# Use with command-line debugging, but not RubyMine
#gem 'debugger'

gem 'bundler'

回答by mistertim

I've noticed this happening when I've tried to bundle installwith a fresh RVM gemset that didn't yet include bundler (as it fell back on the system bundler install which referenced the system ruby).

当我尝试bundle install使用尚未包含捆绑程序的新 RVM gemset时,我注意到发生了这种情况(因为它退回到引用系统 ruby​​ 的系统捆绑程序安装)。

Running gem install bundlerfixed for me.

跑步gem install bundler对我来说是固定的。

回答by Henrik N

None of these worked for me, but I finally figured it out:

这些都不适合我,但我终于想通了:

spring stop

I had a Rails 4 project that uses something called Spring to keep a Rails environment running in the background, for speed.

我有一个 Rails 4 项目,它使用一种叫做 Spring 的东西来保持 Rails 环境在后台运行,以提高速度。

I had started Spring with Ruby 2.1.1 but then I upgraded to 2.1.2 (in Gemfile and .ruby-version). My theory is that Spring kept on running on 2.1.1 and so caused this error.

我已经用 Ruby 2.1.1 开始了 Spring,但后来我升级到了 2.1.2(在 Gemfile 和 .ruby 版本中)。我的理论是 Spring 在 2.1.1 上继续运行,因此导致了这个错误。

回答by Magne

Heroku Toolbeltmay be causing it if you are using the herokucommand, or more specifically, using bundle exec heroku, which you should never do. If you can fix your problem by removing bundle execin front of your herokucalls, then try that first. If not, then follow what is suggested below.

如果您正在使用heroku命令,或者更具体地说,使用bundle exec heroku,则Heroku Toolbelt可能会导致它,您永远不应该这样做。如果您可以通过bundle execheroku通话前删除来解决问题,请先尝试。如果没有,请按照下面的建议进行操作。



Update February 25, 2017:
Heroku Toolbelt have been renamed to Heroku CLI. See these links for updated install/uninstall instructions:
https://devcenter.heroku.com/articles/heroku-cli
https://github.com/heroku/cli

2017 年 2 月 25 日更新:
Heroku Toolbelt 已重命名为 Heroku CLI。有关更新的安装/卸载说明,请参阅这些链接:
https: //devcenter.heroku.com/articles/heroku-cli
https://github.com/heroku/cli

Original post is provided unedited below (for legacy instructions):

下面提供未经编辑的原始帖子(用于遗留说明):



If you have installed the Heroku toolbelt from the official site:

如果您已经从官方网站安装了 Heroku 工具带:

At the top of /usr/bin/herokuit probably says something like #!/usr/local/heroku/ruby/bin/ruby

/usr/bin/heroku它的顶部可能会说类似的东西#!/usr/local/heroku/ruby/bin/ruby

Try running /usr/local/heroku/ruby/bin/ruby -vand see if it outputs ruby 1.9.3.

尝试运行/usr/local/heroku/ruby/bin/ruby -v,看看它是否输出 ruby​​ 1.9.3。

https://github.com/heroku/toolbelt/issues/53

https://github.com/heroku/toolbelt/issues/53

? heroku --version
heroku-toolbelt/3.26.1 (x86_64-darwin10.8.0) ruby/1.9.3

Notice the 1.9.3 specified at the end there.

请注意此处末尾指定的 1.9.3。

--- Do NOTuse this page, and its packaged installer, to install the Heroku CLI on OSX:

---请不要使用此页面,其包装的安装,对安装OSX Heroku的CLI:

https://toolbelt.heroku.com/

https://toolbelt.heroku.com/

Because the technical details listed there are important:

因为那里列出的技术细节很重要:

The heroku command line client will be installed into /usr/local/heroku and /usr/local/heroku/bin will be added to your PATH.

heroku 命令行客户端将安装到 /usr/local/heroku 中,/usr/local/heroku/bin 将添加到您的 PATH 中。

This is detrimental, because RVM will then do this:

这是有害的,因为 RVM 会这样做:

? rvm current
ruby-2.1.1

? heroku --version
heroku-toolbelt/3.26.1 (x86_64-darwin10.8.0) ruby/1.9.3

There is that irritating 1.9.3 version, even when I've specified another Ruby version with RVM.

即使我已经使用 RVM 指定了另一个 Ruby 版本,1.9.3 版本也是令人恼火的。

Uninstall the Heroku toolbelt

卸载 Heroku 工具带

There is no official uninstaller for OSX, write +1 here if you think there should be one: https://github.com/heroku/toolbelt/issues/8

OSX 没有官方卸载程序,如果您认为应该有一个,在此处写 +1:https: //github.com/heroku/toolbelt/issues/8

Uninstall manually (moving to Trash, to keep a backup, in case something fails):

手动卸载(移至废纸篓,以保留备份,以防万一出现故障):

mv ~/.heroku ~/.Trash
sudo mv /usr/local/heroku ~/.Trash
sudo mv /usr/bin/heroku ~/.Trash

Install the Heroku toolbelt with homebrew instead

使用自制软件安装 Heroku 工具带

Because it links the current RVM version to the Heroku-toolbelt correctly. Run:

因为它将当前 RVM 版本正确链接到 Heroku-toolbelt。跑:

brew install heroku-toolbelt

brew install heroku-toolbelt

Heroku toolbelt will then be installed only in this location:

Heroku toolbelt 将只安装在这个位置:

/usr/local/Cellar/heroku-toolbelt/3.21.4

/usr/local/Cellar/heroku-toolbelt/3.21.4

(You could also remove it easily with brew uninstall heroku-toolbeltif you wanted.)

(如果需要,您也可以轻松地将其删除brew uninstall heroku-toolbelt。)

Testing the install:

测试安装:

? rvm current
ruby-2.0.0-head@bloggery

? rvm list

rvm rubies

=* ruby-2.0.0-head [ x86_64 ]
   ruby-2.1-head [ x86_64 ]
   ruby-2.1.1 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

? rvm use ruby-2.1.1
Using /Users/Username/.rvm/gems/ruby-2.1.1

? rvm current
ruby-2.1.1

? heroku --version
heroku-toolbelt/3.26.1 (x86_64-darwin12.0) ruby/2.1.1
You have no installed plugins.

? rvm use ruby-2.0.0-head
Using /Users/Username/.rvm/gems/ruby-2.0.0-head

? heroku --version
heroku-toolbelt/3.26.1 (x86_64-darwin13.4.0) ruby/2.0.0
You have no installed plugins.

Notice it now says 2.0.0 at the end of that last command there. You now run the Heroku client with whatever rvm currentruby version you have specified in RVM.

请注意,它现在在最后一个命令的末尾显示 2.0.0。现在,rvm current您可以使用在 RVM 中指定的任何ruby 版本运行 Heroku 客户端。

回答by dysruption

If you type rvm listand it shows a 2.0 version of Ruby as your current version and you are still getting this error, typing rvm use (ruby version)fixed this issue for me.

如果您键入rvm list并显示 Ruby 的 2.0 版本作为您的当前版本,并且您仍然收到此错误,请键入rvm use (ruby version)为我修复了此问题。

回答by Clay Bridges

If you are using a Ruby version manager like RVM or rbenv, then create, in the top-level directory of your project, a file named .ruby-versioncontaining the version spec'd in your Gemfile, e.g.:

如果您正在使用 RVM 或 rbenv 之类的 Ruby 版本管理器,请在项目的顶级目录中创建一个名为的文件,.ruby-version其中包含 Gemfile 中的版本规范,例如:

2.0.0

That apparently is the cross-{rbenv,rvm}way of spec'ing the version now.

这显然是{rbenv,rvm}现在规范版本的交叉方式。

回答by Daniel Kang

"I had the same problem using rbenv, installed via brew.

“我在使用 rbenv 时遇到了同样的问题,通过 brew 安装。

I couldn't figure it out, tried all of the above, I ended up switching to rvm which solved it."

我无法弄清楚,尝试了上述所有方法,最终切换到 rvm 解决了它。”

In response to this post, you have to make sure you run rbenv rehashafter you install a ruby version. That seemed to work for me when I ran into the same problem.

为了回应这篇文章,您必须确保rbenv rehash在安装 ruby​​ 版本后运行。当我遇到同样的问题时,这似乎对我有用。

回答by PallavSharma

In my case I used rvm get headto update the RVM version and it worked.

就我而言,我曾经rvm get head更新过 RVM 版本并且它工作正常。

回答by Chris Hanson

ruby-switch was removed from ubuntu 14.04 and up. I'll leave this answer for posterity, but you probably need a different solution. Check out "Install ruby 2.0 without ruby-switch?" as well.

ruby-switch 已从 ubuntu 14.04 及更高版本中删除。我会把这个答案留给后人,但你可能需要一个不同的解决方案。也请查看“在没有 ruby​​-switch 的情况下安装 ruby​​ 2.0?”。



If you have you've installed a new version of Ruby but are still getting errors about the Gemfile mismatch, you probably need to use ruby-switchto set the new version of Ruby as your default:

如果您已经安装了新版本的 Ruby,但仍然收到有关 Gemfile 不匹配的错误,您可能需要使用ruby-switch将新版本的 Ruby 设置为默认值:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install ruby2.1 ruby2.1-dev
sudo ruby-switch --set ruby2.1
sudo gem install bundler

回答by asgeo1

I had this issue after upgrading Ruby versions via rbenv. I tried the spring stopcommand that someone mentioned above.

通过rbenv升级Ruby版本后我遇到了这个问题。我尝试了spring stop上面有人提到的命令。

When I ran that I got another message suggesting that I run gem pristine --all

当我跑步时,我收到了另一条建议我跑步的消息 gem pristine --all

Warning: Running gem pristine --all to regenerate your installed gemspecs will improve the startup performance of Spring.

警告:运行 gem pristine --all 来重新生成已安装的 gemspecs 将提高 Spring 的启动性能。

So I ran that command, and then things went back to normal.

所以我运行了那个命令,然后一切又恢复正常。