How to fix “Your Ruby version is 1.9.3, but your G

2019-01-03 06:42发布

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

17条回答
疯言疯语
2楼-- · 2019-01-03 06:42

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'
查看更多
在下西门庆
3楼-- · 2019-01-03 06:42

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

查看更多
Bombasti
4楼-- · 2019-01-03 06:43

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楼-- · 2019-01-03 06:43

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.

查看更多
你好瞎i
6楼-- · 2019-01-03 06:43

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
查看更多
走好不送
7楼-- · 2019-01-03 06:44

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
查看更多
登录 后发表回答