74

When I try to bundle install I get the following message:

Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0

In my Gemfile I have the following:

ruby '2.1.0'

And when I run ruby -v in the console I get:

ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]

What does Ruby 2.1.0p0 mean? What version should I have in my Gemfile and why does the error tell me I have Ruby version 2.0.0?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
stecd
  • 1,681
  • 6
  • 19
  • 28

24 Answers24

110

Run

gem install bundler

or

gem update bundler 

which may fix your problem.

For all new installed versions of Ruby you should update or install a new bundler.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
  • 11
    I'm running into the exact same issue, but this is not fixing it for me. Can you elaborate a bit more on why this would work? After installing bundler, I still get `Your Ruby version is 2.0.0, but your Gemfile specified 2.0.0-p645`. `rbenv` does not even _have_ 2.0.0. – Joost Jul 26 '15 at 22:59
  • 7
    ha. this even worked for my 2.0.0 vs 2.2.4 problem, although i got a ```Nothing to update``` message when updating bundler. ¯\_(ツ)_/¯ – manmal Mar 11 '16 at 11:36
  • Had the same problem, my gemfile specified 2.2.2 and I also had a .ruby-version file. `rvm info` also gave me 2.2.2 - gem update bundler fixed the error :) didn't have to mess with `rbenv`. – Adam Cooper Mar 17 '16 at 07:54
  • 5
    If you just installed that version, restarting your shell may help as well. – Courtney Pattison Mar 18 '17 at 17:58
  • also received the `Nothing to update` message, but `gem update bundler` worked immediately. – Mark Peterson Mar 29 '18 at 01:26
  • same here, received Nothing to Update message but it works somehow. not sure why... – Realizt30 Apr 05 '20 at 06:24
15

In the top-level directory of your project, create a file named .ruby-version containing (wait for it...)

2.1.0

That apparently is the cross-{rbenv,rvm} way of spec'ing the version now.

Clay Bridges
  • 11,602
  • 10
  • 68
  • 118
14

For me, none of the answers helped. I fixed it closing and opening again the terminal.

  • This worked for me as well, however keep in mind that this is because the terminal window we were in had some sort of different source loaded. Our default source happened to work. – KazaJhodo Aug 28 '18 at 15:04
13

If you get this in a Rails project, and you recently upgraded your Ruby version you might have spring still running with the old version of Ruby.

./bin/spring stop

will fix this.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Myers Carpenter
  • 939
  • 1
  • 9
  • 12
7

None of the other suggestions was working for me. On the server, I had to do:

rvm --default use [correct version number]

Loren
  • 3,476
  • 3
  • 23
  • 15
4

brew cleanup ruby worked for me as I use HomeBrew to install Ruby.

I recently updated Ruby through HomeBrew but HomeBrew did not remove the older version. brew cleanup ruby will delete the older version of Ruby.

ethicalhack3r
  • 1,062
  • 3
  • 15
  • 16
4

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 
3

If you are using Capistrano you should also check your deploy.rb file for the set :rbenv_ruby configuration.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Darme
  • 6,984
  • 5
  • 37
  • 52
3

I got this after upgrading with ruby-install. Fixed this with:

gem install bundler

followed by:

$HOME/.rubies/ruby-2.4.1/bin/bundle

It shouldn't be necessary to specify the path as which bundle indicates it's already using this path. But it gives the version error if running bundle without the path. I don't know why?

mahemoff
  • 44,526
  • 36
  • 160
  • 222
3

Thanks for the info about installing / updating bundler but it didn't work for me. I had to do rbenv rehash

MarkP
  • 171
  • 1
  • 5
2

If you are using rbenv to manage your ruby environments you can run rbenv local 2.1.0 within your project directory to set the version of ruby your gemfile asks for.

Tim
  • 21
  • 2
2

NONE of the above answers worked for me, but

$ gem pristine --all

did the trick for me

buona fortuna

Salomanuel
  • 897
  • 10
  • 22
2

I struggled with something very similar, just different versions. I finally fixed it by going to RubyGems and placing the latest version of bundler in my gemfile, which currently is:

gem 'bundler', '~> 2.1', '>= 2.1.4'

There was still an issue, but after that, I ran:

gem update --system

And it resolved the mixed-up versions of Ruby in the rails project folder. You may have to restart the terminal before you do this. Also, I commented out the bundler gem file, it appears the gem update --system command is what really resolved it.

I got it from here:

Dan
  • 139
  • 1
  • 6
1

For more advanced projects .versions.conf is supported, where more than the Ruby version can be specified.

Generating .versions.conf:

rvm --create --versions-conf use 1.9.3@my_app

Example .versions.conf:

ruby=jruby-1.6.8
ruby-gemset=my_app
env-JRUBY_OPTS=--1.9
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
1

Make sure your server configuration points to the correct ruby installation.

I had already updated my Ruby version in the .ruby-version file and that didn't fix it. ruby -v also showed the correct version, but I had forgotten to update my server config.

For example, with rbenv, NGINX, and Pushion Passenger I had in my NGINX server block:
passenger_ruby /Users/myusername/.rbenv/versions/2.3.1/bin/ruby;

And I needed to change to...
passenger_ruby /Users/myusername/.rbenv/versions/2.3.3/bin/ruby;

Then restarted NGINX and it worked.

Allen
  • 2,717
  • 2
  • 30
  • 34
1

This could happen when you install new version of ruby and update .ruby-version and Gemfile to the new version without doing install all the gems for new version of ruby first. So do the

$ bundle install

and you might as well need to source .profile or restart your shell.

Ken Ratanachai S.
  • 3,307
  • 34
  • 43
1

If you are using rbenv just run

rbenv local 2.0.0 

Then

bundle install
Babatunde Mustapha
  • 2,131
  • 20
  • 21
1

I opened Gemfile and replaced 2.7.1 with my own version of ruby 2.7.0 Everything is okay right now.

1

Had the same problem and I'm working with rbenv

Those are the steps that helped me fix my problem:

  1. First in terminal, type which bundle. For me this gave: /usr/local/bin/bundle

  2. Again in terminal try which ruby. In my case this gave: /Users/Mahmoud/.rbenv/shims/ruby

The problem here thus is that bundle isn't using the same ruby version from rbenv. So the path needs fixing. In other words I need to tell my terminal to use the rbenv version of bundle when I use bundle install.

So step 3: For me I personally already had the path set in ~/.bash_profile:

export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"

but apparently this was not enough as I was using zsh. Had to add those same 2 lines to ~/.zshrc as well.

  1. Restart terminal

Now bundle install is working as expected and which bundle gives:

/Users/Mahmoud/.rbenv/shims/bundle

indicating that the problem was just that bundle was using the wrong ruby.

So if you have this problem, just make sure ~/.bash_profile and ~/.zshrc have the correct path by adding the 2 lines indicated above. If this didnt work take a deep dive into paths to make sure that before starting which bundle gives the equivalent of:

/Users/Mahmoud/.rbenv/shims/bundle
Dharman
  • 30,962
  • 25
  • 85
  • 135
mrateb
  • 2,317
  • 5
  • 27
  • 56
0

Had the same error. Doing the following fixed it. I was using ruby 2.5.5 and rbenv. Upgraded from 2.5.1.

  • rbenv rehash
  • gem uninstall bundler
  • gem install bundler
  • gem install bundler:1.17.3 (my app needed specific bundler -v 1.17.3)
  • gem install rails
0

I solved this problem by updating my ruby version to ruby '2.4.0' Then bundle install

nourza
  • 2,215
  • 2
  • 16
  • 42
0

Simply closing the terminal I was working on and opening a new one worked for me. Sometimes, updates are not effected immediately until a session is closed. I have found this as the case with many rails errors I faced.

0

I clean and install with that:

sudo gem pristine --all

and install again:

bundle install

Idan
  • 3,604
  • 1
  • 28
  • 33
-3

I face the error msg

Your Ruby version is 2.5.1, but your Gemfile specified 2.3.0

and solved by the following steps:

  1. open Gemfile which located at your directory.
  2. change ruby '2.3.0' to ruby '2.5.1' and save the Gemfile
  3. go back to items and run bundle update.

the issue is perfectly solved.

Jerome Li
  • 1,492
  • 14
  • 20
  • 1
    This is not a solution. This is a workaround. What if the code requires version `2.3.0` compulsorily. – JaydeepW Aug 06 '18 at 05:31
  • It is a terrible idea to just change the project required ruby version. Many things can stop working. The developer needs to use the project ruby version. – Leticia Esperon Aug 07 '18 at 17:55