12

I entered a existing ruby application, and type:

$ rails s

wanted to start rails server here. but it said:

Your Ruby version is 1.8.7, but your Gemfile specified 1.9.3

Actually, I had a 1.8.7, but I deleted it. And if I do:

$ ruby -v

it said: ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-darwin11.4.2]

So I don't know how can I fix it. Can you give me a help?

Charles
  • 50,943
  • 13
  • 104
  • 142
Yuqing Huang
  • 785
  • 2
  • 7
  • 7

6 Answers6

12

If you are using rvm, run this:

$ rvm use 1.9.3
Naoise Golden
  • 8,793
  • 4
  • 49
  • 65
5

try using bundler

bundle exec rails s
Yuriy Goldshtrakh
  • 2,014
  • 1
  • 11
  • 7
5

I had similar problem:

$ bundle install
Your Ruby version is 2.1.0, but your Gemfile specified 1.9.3

but:

$ ruby -v
1.9.3-p484
$ which ruby
/home/malo/.rvm/rubies/ruby-1.9.3-p484/bin/ruby

I've found five answers: 1, 2, 3, 4, 5. Also it was open issue on . However, I've resolved the problem as follows:

  1. Got path to my :

    $ which bundle
    /home/malo/.rvm/gems/ruby-1.9.3-p484@global/bin/bundle
    
  2. Opened it to edit (or just it), and saw that it has invalid link to ruby in the first line:

    $ cat $(which bundler)|head -n 1 
    #!/home/malo/.rvm/rubies/ruby-2.1.0/bin/ruby
    
  3. Then I get the path to current valid ruby, and just replaced that invalid with it:

    $ which ruby
    /home/malo/.rvm/rubies/ruby-1.9.3-p484/bin/ruby
    

    Of course you can also try replace it with the common form:

    #!/usr/bin/env ruby
    

    This should pick up the currently used ruby version.

Community
  • 1
  • 1
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69
  • 2
    All of the other answers I could find turned out to be useless, but this was spot on. I fixed the issue, and I'm back up and running. Also, I love you. – Brandon Aaskov Mar 25 '14 at 22:33
  • is the path in your bundler this line: export RBENV_ROOT="/Users/usernamehere/.rbenv" – gpr Jul 01 '14 at 08:16
3

I found out the reason I was getting this error was that I was shelling out to a Heroku command line program inside of my configuration files and Heroku Toolbelt comes with it's own version of Ruby.

The two solutions to that problem are to either not shell out to Heroku or use a Bundler.with_clean_env block instead of the backticks to shell out the heroku command.

webdevguy
  • 975
  • 10
  • 17
1

Please try this:

 1. Open your gemfile
 2. Specify rails version
 3. Run bundle update
 4. Run rails server - rails s
suresh gopal
  • 3,138
  • 6
  • 27
  • 58
0

Every now and then this happens with me. However I often don't like switching ruby versions here and there. So instead what I do is I just go to the Gemfile and switch the ruby version to the one that I am using. Doing this allows me to fire up my server and keep working on things.

so for instance, right now for the app i'm working on, my Gemfile is at

ruby ENV["CUSTOM_RUBY_VERSION"] || "2.1.6"

and I would just alter it to

ruby ENV["CUSTOM_RUBY_VERSION"] || "1.9.3"
kdweber89
  • 1,984
  • 2
  • 19
  • 29