5

I'm using rbenv and I have the follow error when I execute rails s

Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2

I was reading this thread: Mavericks, RBENV, Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1

But the error persist.

rails -v
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2

and the commands

sudo gem install bundler 
rbenv rehash

$ which ruby /usr/bin/ruby

$ bundle exec which ruby Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2

doenst solve the problem. I'm doing something wrong?

Community
  • 1
  • 1
Benjamin RD
  • 11,516
  • 14
  • 87
  • 157

3 Answers3

4

What version of ruby are you using?

ruby -v

It sounds like the Gemfile has a ruby requirement listed for 2.1.2. You may need to install that version:

rbenv install 2.1.2

Then you may need to tell rbenv to use that version for that project:

rbenv local 2.1.2

It looks like the rbenv team/community decided against adding support for ruby versions specified in the Gemfile. Reference: https://github.com/sstephenson/rbenv/issues/223

Zach Dennis
  • 1,754
  • 15
  • 19
  • 1
    I tried it, but the same problem. `ruby -v` > ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13] – Benjamin RD Nov 23 '14 at 23:53
  • What happened after you ran "rbenv install 2.1.2" ? If you do "rbenv list" does it show you that 2.1.2 is installed? You may need to cd out of the directory and cd back in after the "rebind local 2.1.2" step. – Zach Dennis Nov 23 '14 at 23:54
  • were installed a lot of packages, now if I execute `rbenv local 2.1.2` didnt display any error, but my `ruby -v` still the same – Benjamin RD Nov 23 '14 at 23:56
  • Is there a `.ruby-version` file and did you cd out of the directory and back in? – Zach Dennis Nov 23 '14 at 23:57
  • No, any file, that is only in may Gemfile, but the version specified it's 2.1.2 – Benjamin RD Nov 24 '14 at 00:17
  • I know the ruby version is in your Gemfile. The problem is that you need you local "ruby" executable to point to the 2.1.2 version. Since you are using rbenv you need to tell it to install and then use ruby 2.1.2. The "rbenv local 2.1.2" command above tells rbenv to use ruby 2.1.2. It should also write out to a .ruby-version file in that directory. Please read the documentation for rbenv to understand the program you are using to manage your versions of Ruby: https://github.com/sstephenson/rbenv#rbenv-local – Zach Dennis Nov 24 '14 at 15:41
  • I have installed ruby 2.2.4, rbenv rehash, rbenv local 2.2.4, ruby 2.2.4 is what is specified by my gemfile. ruby -v => 2.2.4. I am still seeing this error Your Ruby version is 2.0.0, but your Gemfile specified 2.2.4 – BM5k Apr 15 '16 at 23:41
3

If you get this in a Rails project, and you recently upgraded your ruby version you might have spring running with the old version of ruby. ./bin/spring stop will fix this.

Myers Carpenter
  • 939
  • 1
  • 9
  • 12
  • I had not recently upgraded, but this did solve the problem. In my case, all commands such as "which ruby", "bundle exec which ruby", "rvm list" all said I was using the correct ruby version, but "rails console" from the same command-prompt, continued trying to use another version. Thank you so much. – JosephK Aug 23 '15 at 12:35
0

If it's macOS, and your new Ruby is from homebrew, try sudo gem bundler

Tauri
  • 1,291
  • 1
  • 14
  • 28