可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I created a Ruby project, but when running bundle update
and bundle install
it returns an error:
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
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
回答1:
If you run ruby -v
you'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.
You should either install Ruby 2.0.0 or change the first line in your Gemfile to specify Ruby 1.9.3.
sample of 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'
回答2:
I've noticed this happening when I've tried to bundle install
with a fresh RVM gemset that didn't yet include bundler (as it fell back on the system bundler install which referenced the system ruby).
Running gem install bundler
fixed for me.
回答3:
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.
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.
回答4:
Heroku Toolbelt may be causing it if you are using the heroku
command, or more specifically, using bundle exec heroku
, which you should never do. If you can fix your problem by removing bundle exec
in front of your heroku
calls, then try that first. If not, then follow what is suggested below.
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
Original post is provided unedited below (for legacy instructions):
If you have installed the Heroku toolbelt from the official site:
At the top of /usr/bin/heroku
it probably says something like #!/usr/local/heroku/ruby/bin/ruby
Try running /usr/local/heroku/ruby/bin/ruby -v
and see if it outputs ruby 1.9.3.
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.
--- Do NOT use this page, and its packaged installer, to install the Heroku CLI on OSX:
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.
This is detrimental, because RVM will then do this:
› 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.
Uninstall the Heroku toolbelt
There is no official uninstaller for OSX, write +1 here if you think there should be one: 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
Because it links the current RVM version to the Heroku-toolbelt correctly. Run:
brew install heroku-toolbelt
Heroku toolbelt will then be installed only in this location:
/usr/local/Cellar/heroku-toolbelt/3.21.4
(You could also remove it easily with brew uninstall heroku-toolbelt
if you wanted.)
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 current
ruby version you have specified in RVM.
回答5:
If you type rvm list
and 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.
回答6:
"I had the same problem using rbenv, installed via brew.
I couldn't figure it out, tried all of the above, I ended up switching to rvm which solved it."
In response to this post, you have to make sure you run rbenv rehash
after you install a ruby version. That seemed to work for me when I ran into the same problem.
回答7:
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-version
containing the version spec'd in your Gemfile, e.g.:
2.0.0
That apparently is the cross-{rbenv,rvm}
way of spec'ing the version now.
回答8:
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.
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-switch
to set the new version of Ruby as your default:
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
回答9:
In my case I used rvm get head
to update the RVM version and it worked.
回答10:
I found that reinstalling RVM did the trick when this error occured, as any other suggestion didn't work.
回答11:
I had this issue after upgrading Ruby versions via rbenv. I tried the spring stop
command that someone mentioned above.
When I ran that I got another message suggesting that I run gem pristine --all
Warning: Running gem pristine --all to regenerate your installed
gemspecs will improve the startup performance of Spring.
So I ran that command, and then things went back to normal.
回答12:
I had the same problem using rbenv, installed via Homebrew.
I couldn't figure it out, tried all of the above, so I ended up switching to RVM which solved it.
回答13:
I discovered my rake or rails script under the bin directory was using another version of ruby. I compared two rake scripts from two servers (production and development) and it showed me they were using different ruby versions. So I had to update accordingly.
1c1
< #!/usr/bin/env ruby
---
> #!/usr/bin/env ruby1.9.1
回答14:
Came across this error while using the passenger gem. Since I installed this gem with sudo access, it took a default version of ruby on its own. I believe the reason could be that ruby was installed without sudo access on my system and passenger didn't know the actual version of ruby to be used.
However, installing the gem and its apache module without sudo access fixed the problem.
回答15:
I share this tidbit in a moment of great relief after having finally solved a problem that's been haunting me for months.
rails new myapp
//Your Ruby version is 2.1.5, but your Gemfile specified 2.0.0
I tried literally every solution to this problem that I could find on the web and at the end of the day it turns out my problem was caused because I had accidentally installed a Rails app in Users/MyName, and it was reading that Gemfile.
So before you go try the various other solutions offered here, you may want to take a second to confirm that you have not done something similar.
回答16:
I am running the Windows dev environment.
I just added C:\Ruby22-x64\bin
in my path variable before heroku\bin
entry.
回答17:
I had this exact issue - just a few seconds after watching Mac OSX Terminal confirm that Ruby 2.0.0 was successfully installed.
Mac OSX ships with an out-of-date version of Ruby already installed and set as the default Ruby. In order to correct the issue, you can install "JewelryBox", a charming and lovely app that gives you a GUI to view and manage multiple rubies (helpful if you have multiple dev environments on one Mac). You can use it to deselect Mac OSX's default Ruby and select your newly installed Ruby.