How to fix "Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0"

Ruby on-RailsRuby

Ruby on-Rails Problem Overview


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

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

I've noticed this happening when I've tried to bundle install with a fresh RVM gemset that didn't yet include bundler (as it fell back on the system bundler install which referenced the system ruby).

Running gem install bundler fixed for me.

Solution 2 - Ruby on-Rails

None of these worked for me, but I finally figured it out:

spring stop

I had a Rails 4 project that uses something called Spring to keep a Rails environment running in the background, for speed.

I had started Spring with Ruby 2.1.1 but then I upgraded to 2.1.2 (in Gemfile and .ruby-version). My theory is that Spring kept on running on 2.1.1 and so caused this error.

Solution 3 - Ruby on-Rails

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.

Solution 4 - Ruby on-Rails

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'

Solution 5 - Ruby on-Rails

If you type rvm list and it shows a 2.0 version of Ruby as your current version and you are still getting this error, typing rvm use (ruby version) fixed this issue for me.

Solution 6 - Ruby on-Rails

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.

Solution 7 - Ruby on-Rails

"I had the same problem using rbenv, installed via brew.

I couldn't figure it out, tried all of the above, I ended up switching to rvm which solved it."

In response to this post, you have to make sure you run rbenv rehash after you install a ruby version. That seemed to work for me when I ran into the same problem.

Solution 8 - Ruby on-Rails

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

Solution 9 - Ruby on-Rails

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

Solution 10 - Ruby on-Rails

I had this issue after upgrading Ruby versions via rbenv. I tried the spring stop command that someone mentioned above.

When I ran that I got another message suggesting that I run gem pristine --all

> Warning: Running gem pristine --all to regenerate your installed > gemspecs will improve the startup performance of Spring.

So I ran that command, and then things went back to normal.

Solution 11 - Ruby on-Rails

the main reason for this problem is your machine and gemfile using a different ruby version

so there is multiple problems and solutions for this issue you can try the below solutions one by one

1- make sure your machine install and use the same version of your gemfile if your machine not using the same one try to install this version using rvm

$ rvm install ruby_version_you_want

make sure the version installed success by using this command

$ rvm list

and if the new version doesn't set as a default you can set it using this command

$ rvm --default use ruby_version_you_want 

you can check the current ruby version

 $ rvm current 
 $ ruby -v 

2- if you have the same issue check your bundler

  $ gem install bundler
    or
  $ gem update bundler 

3- in some cases spring still using the old version so you need to stop it

$ ./bin/spring stop

4- another case you can type

$ gem pristine --all 

and try to install bundle again

5- also in some cases after install the updated ruby version you just need to restart your terminal.

6- another solution but I didn't recommend it the top-level directory of your project, create a file named .ruby-version containing your active running ruby version

7- if you still have this problem try to remove ruby and install the updated version only

 $ aptitude purge ruby 

Solution 12 - Ruby on-Rails

I found that reinstalling RVM did the trick when this error occured, as any other suggestion didn't work.

Solution 13 - Ruby on-Rails

I had this exact issue - just a few seconds after watching Mac OSX Terminal confirm that Ruby 2.0.0 was successfully installed.

Mac OSX ships with an out-of-date version of Ruby already installed and set as the default Ruby. In order to correct the issue, you can install "JewelryBox", a charming and lovely app that gives you a GUI to view and manage multiple rubies (helpful if you have multiple dev environments on one Mac). You can use it to deselect Mac OSX's default Ruby and select your newly installed Ruby.

Solution 14 - Ruby on-Rails

I had the same problem using rbenv, installed via Homebrew.

I couldn't figure it out, tried all of the above, so I ended up switching to RVM which solved it.

Solution 15 - Ruby on-Rails

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

Solution 16 - Ruby on-Rails

Came across this error while using the passenger gem. Since I installed this gem with sudo access, it took a default version of ruby on its own. I believe the reason could be that ruby was installed without sudo access on my system and passenger didn't know the actual version of ruby to be used.

However, installing the gem and its apache module without sudo access fixed the problem.

Solution 17 - Ruby on-Rails

Suggestion for anybody finding this issue and none of the typical solutions resolve this issue for you, check to see if you have more than one ruby version manager. There are multiple version managers, and some software or install scripts will use different ones. I know of rbenv, rvm, asdf, and at least one other that I don't recall the name of. I had asdf installed by a different tool without realizing it happened and it caused the specified version mismatch.

To check for this execute which ruby and look carefully at the path. If it's not the actual version manager you are expecting, you are suffering from this issue. Simplest fix is to use the one you want, and get rid of the other one. If for some reason you need to keep both, you will probably need to change the order of paths in your shell's .rc file.

Solution 18 - Ruby on-Rails

i was facing the same issue then found and tried below steps

Step1: rvm use jruby-9.2.9.0

Step2: source $HOME/.rvm/scripts/rvm

Solution 19 - Ruby on-Rails

I am running the Windows dev environment.

I just added C:\Ruby22-x64\bin in my path variable before heroku\bin entry.

Solution 20 - Ruby on-Rails

I share this tidbit in a moment of great relief after having finally solved a problem that's been haunting me for months.

rails new myapp
//Your Ruby version is 2.1.5, but your Gemfile specified 2.0.0

I tried literally every solution to this problem that I could find on the web and at the end of the day it turns out my problem was caused because I had accidentally installed a Rails app in Users/MyName, and it was reading that Gemfile.

So before you go try the various other solutions offered here, you may want to take a second to confirm that you have not done something similar.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiontheone1oneView Question on Stackoverflow
Solution 1 - Ruby on-RailsmistertimView Answer on Stackoverflow
Solution 2 - Ruby on-RailsHenrik NView Answer on Stackoverflow
Solution 3 - Ruby on-RailsMagneView Answer on Stackoverflow
Solution 4 - Ruby on-RailsJeremy GreenView Answer on Stackoverflow
Solution 5 - Ruby on-RailsdysruptionView Answer on Stackoverflow
Solution 6 - Ruby on-RailsClay BridgesView Answer on Stackoverflow
Solution 7 - Ruby on-RailsDaniel KangView Answer on Stackoverflow
Solution 8 - Ruby on-RailsPallavSharmaView Answer on Stackoverflow
Solution 9 - Ruby on-RailsChris HansonView Answer on Stackoverflow
Solution 10 - Ruby on-Railsasgeo1View Answer on Stackoverflow
Solution 11 - Ruby on-RailsMohamed NaserView Answer on Stackoverflow
Solution 12 - Ruby on-RailsShaun McDonaldView Answer on Stackoverflow
Solution 13 - Ruby on-RailsDeborahView Answer on Stackoverflow
Solution 14 - Ruby on-RailsFreePenderView Answer on Stackoverflow
Solution 15 - Ruby on-RailsDavid OkwiiView Answer on Stackoverflow
Solution 16 - Ruby on-RailsVPaulView Answer on Stackoverflow
Solution 17 - Ruby on-RailsagbodikeView Answer on Stackoverflow
Solution 18 - Ruby on-RailsMiteshView Answer on Stackoverflow
Solution 19 - Ruby on-RailsmdwpilotView Answer on Stackoverflow
Solution 20 - Ruby on-RailsAlex ColketView Answer on Stackoverflow