Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get the error "Your Ruby version is 2.0.0, but your Gemfile specified 2.2.2" although I have 2.2.2 installed

Tags:

I'm using rbenv and I get the error Your Ruby version is 2.0.0, but your Gemfile specified 2.2.2 when I run the bundle install command in my project. The strange thing is that I've actually got the 2.2.2 version installed (as my Gemfile specifies), and not the 2.0.0 version. (See image below).

enter image description here

I tried the solution offered in this thread: Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0, but it had no effect.

I'm on an MacBook Air with Yosemite if that makes any difference.

Update:

  • which ruby -> Users/myuser/.rbenv/shims/ruby
  • ruby -v -> ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
  • rbenv global 2.2.2 and rbenv rehash, has no effect
  • which bundle -> /usr/bin/bundle
  • gem env-> - GEM PATHS:
    • /Users/myuser/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0
    • /Users/myuser/.gem/ruby/2.2.0
like image 591
bork Avatar asked Aug 20 '15 14:08

bork


People also ask

How do I specify a Gemfile version?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .

How do you update a Ruby gem to a specific version?

The correct way to update the version of a gem to a specific version is to specify the version you want in your Gemfile, then run bundle install . As for why your command line was failing, there is no -version option.

How do I use Gemfile in Ruby?

A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code. For instance, in a Rails application, place the Gemfile in the same directory as the Rakefile .

What is Gemfile in Ruby on rails?

A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.


2 Answers

You have a system bundler installed, and rbenv is always trying to pick that up. Based on the steps on this site:

  • Make sure you are using the proper gem version. Type which gem and gem env and check that it points to your 2.2.2 ruby version
  • Install bundler using this gem: gem install bundler
  • Once this version of bundler is installed run rbenv rehash
  • Call which bundler, make sure it now points to the shim version of bundler

gem install might not work properly with rbenv if you have your GEM_HOME or GEM_PATH variable overriden, or if you have custom configs in ~/.gemrc, ~/.gem/gemrc or /etc/gemrc. Check the result of gem env, it should say something like this:

- INSTALLATION DIRECTORY: /Users/<youruser>/.rbenv/versions/<ruby-version>/lib/ruby/gems/<ruby-framework-version>
(...)
- GEM PATHS:
  - /Users/<youruser>/.rbenv/versions/<ruby-version>/lib/ruby/gems/<ruby-framework-version>

(note the ruby-framework-version doesn't always exactly match the ruby-version. If the ruby-version is the correct one then the path should be alright)

if not, make sure you don't have any environment overrides or custom configs inside the files mentioned above.

You might also want to try to remove all bundlers from your machine and try again afterwards:

  • rbenv local system
  • gem uninstall bundler
  • rbenv local 2.2.2
  • gem uninstall bundler
like image 135
SztupY Avatar answered Oct 29 '22 19:10

SztupY


I finally solved my problem using this thread Bundler not working with rbenv, could not find [gem],

by using these commands after reinstalling rbenv:

  • gem install --no-ri --no-rdoc bundler
  • rbenv rehash
  • bundle --path=vendor/bundle
like image 31
bork Avatar answered Oct 29 '22 18:10

bork