可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When I try to bundle install I get the following message:
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0
In my Gemfile I have the following:
ruby '2.1.0'
And when I run ruby -v
in the console I get:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
What does Ruby 2.1.0p0 mean? What version should I have in my Gemfile and why does the error tell me I have Ruby version 2.0.0?
回答1:
Run
gem install bundler
or
gem update bundler
which may fix your problem.
For all new installed versions of Ruby you should update or install a new bundler.
回答2:
In the top-level directory of your project, create a file named .ruby-version
containing (wait for it...)
2.1.0
That apparently is the cross-{rbenv,rvm}
way of spec'ing the version now.
回答3:
If you get this in a Rails project, and you recently upgraded your Ruby version you might have spring still running with the old version of Ruby.
./bin/spring stop
will fix this.
回答4:
I got this after upgrading with ruby-install. Fixed this with:
gem install bundler
followed by:
$HOME/.rubies/ruby-2.4.1/bin/bundle
It shouldn't be necessary to specify the path as which bundle
indicates it's already using this path. But it gives the version error if running bundle
without the path. I don't know why?
回答5:
If you are using Capistrano you should also check your deploy.rb
file for the set :rbenv_ruby
configuration.
回答6:
If you are using rbenv to manage your ruby environments you can run rbenv local 2.1.0
within your project directory to set the version of ruby your gemfile asks for.
回答7:
For me, none of the answers helped. I fixed it closing and opening again the terminal.
回答8:
For more advanced projects .versions.conf is supported, where more than the Ruby version can be specified.
Generating .versions.conf:
rvm --create --versions-conf use 1.9.3@my_app
Example .versions.conf:
ruby=jruby-1.6.8
ruby-gemset=my_app
env-JRUBY_OPTS=--1.9
回答9:
Make sure your server configuration points to the correct ruby installation.
I had already updated my Ruby version in the .ruby-version
file and that didn't fix it. ruby -v
also showed the correct version, but I had forgotten to update my server config.
For example, with rbenv, NGINX, and Pushion Passenger I had in my NGINX server block:
passenger_ruby /Users/myusername/.rbenv/versions/2.3.1/bin/ruby;
And I needed to change to...
passenger_ruby /Users/myusername/.rbenv/versions/2.3.3/bin/ruby;
Then restarted NGINX and it worked.
回答10:
Thanks for the info about installing / updating bundler but it didn't work for me.
I had to do rbenv rehash
回答11:
brew cleanup ruby
worked for me as I use HomeBrew to install Ruby.
I recently updated Ruby through HomeBrew but HomeBrew did not remove the older version. brew cleanup ruby
will delete the older version of Ruby.
回答12:
This could happen when you install new version of ruby and update .ruby-version and Gemfile to the new version without doing install all the gems for new version of ruby first. So do the
$ bundle install
and you might as well need to source .profile or restart your shell.
回答13:
I face the error msg
Your Ruby version is 2.5.1, but your Gemfile specified 2.3.0
and solved by the following steps:
- open Gemfile which located at your directory.
- change
ruby '2.3.0'
to ruby '2.5.1'
and save the Gemfile
- go back to items and run bundle update.
the issue is perfectly solved.