Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Erroneous Bundler::RubyVersionMismatch #2489

Closed
ichilton opened this issue May 30, 2013 · 18 comments
Closed

Erroneous Bundler::RubyVersionMismatch #2489

ichilton opened this issue May 30, 2013 · 18 comments

Comments

@ichilton
Copy link

I'm trying to run a rake task on a rails app, and am getting this error:

/home/vagrant/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/definition.rb:361:in     `validate_ruby!': Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)
    from /home/vagrant/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
    from /home/vagrant/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
rake aborted!

As you can see from the paths in the error though, I am running 2.0.0:

$ ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux]

$ bundle -v
Bundler version 1.3.5

$ gem env
RubyGems Environment:

  • RUBYGEMS VERSION: 2.0.3
  • RUBY VERSION: 2.0.0 (2013-05-14 patchlevel 195) [x86_64-linux]
  • INSTALLATION DIRECTORY: /home/vagrant/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0
  • RUBY EXECUTABLE: /home/vagrant/.rbenv/versions/2.0.0-p195/bin/ruby
  • EXECUTABLE DIRECTORY: /home/vagrant/.rbenv/versions/2.0.0-p195/bin
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86_64-linux
  • GEM PATHS:
    • /home/vagrant/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0
    • /home/vagrant/.gem/ruby/2.0.0
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :backtrace => false
    • :bulk_threshold => 1000
  • REMOTE SOURCES:
@ichilton
Copy link
Author

One thought is that it's something to do with rbenv and trying to run something using global ruby (1.9.3) instead of local ruby (2.0.0), but I can't work out why...?

@indirect
Copy link
Member

You may have a hard-coded shebang in the executable you are running. You can check it with "head which rake" or whatever command you are trying to run.

On Thu, May 30, 2013 at 9:26 PM, Ian Chilton notifications@github.com
wrote:

One thought is that it's something to do with rbenv and trying to run something using global ruby (1.9.3) instead of local ruby (2.0.0), but I can't work out why...?

Reply to this email directly or view it on GitHub:
#2489 (comment)

@ichilton
Copy link
Author

rake is an rbenv shim (in ~/.rbenv/shims/rake)

and starts with this:

$ head which rake
#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x

@indirect
Copy link
Member

Sounds like an rbenv issue, then. Maybe you should ask them?

On Thu, May 30, 2013 at 11:42 PM, Ian Chilton notifications@github.com
wrote:

rake is an rbenv shim (in ~/.rbenv/shims/rake)
and starts with this:
$ head which rake
#!/usr/bin/env bash
set -e

[ -n "$RBENV_DEBUG" ] && set -x

Reply to this email directly or view it on GitHub:
#2489 (comment)

@ichilton
Copy link
Author

I was wondering that - thanks.

@ichilton
Copy link
Author

rbenv guys are saying it's bundler's problem: rbenv/rbenv#400

It's not system ruby since the stack trace comes from:

/home/vagrant/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5

which clearly indicates that you're running 2.0. I would rather believe this is a bug with Bundler's version check.

@indirect
Copy link
Member

Well, as you can see from the backtrace you originally posted here, you are somehow loading the Bundler installed into Ruby 2... From the Rubygems installed for 1.9 in /usr/lib. Bundler is correct that you're running it on the wrong version of ruby.

On Fri, May 31, 2013 at 4:12 PM, Ian Chilton notifications@github.com
wrote:

rbenv guys are saying it's bundler's problem: rbenv/rbenv#400
It's not system ruby since the stack trace comes from:
/home/vagrant/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/bundler-1.3.5

which clearly indicates that you're running 2.0. I would rather believe this is a bug with Bundler's version check.

Reply to this email directly or view it on GitHub:
#2489 (comment)

@ichilton
Copy link
Author

Yeah, but is that bundler or rbenv!?

@indirect
Copy link
Member

Bundler is a .rb file and has absolutely no control or say over what ruby interpreter is reading that file and running the code. Your system environment is what determines that.

On Fri, May 31, 2013 at 5:45 PM, Ian Chilton notifications@github.com
wrote:

Yeah, but is that bundler or rbenv!?

Reply to this email directly or view it on GitHub:
#2489 (comment)

@ichilton
Copy link
Author

Yes, but it's Bundler that's doing the version check and erroring.

Also, I just removed rbenv and tried chruby and ruby-install - and it's doing the exact same thing as rbenv and ruby-build.

/home/vagrant/.gem/ruby/2.0.0/gems/bundler-1.3.5/lib/bundler/definition.rb:361:in `validate_ruby!': Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)
  from /home/vagrant/.gem/ruby/2.0.0/gems/bundler-1.3.5/lib/bundler.rb:116:in `setup'
  from /home/vagrant/.gem/ruby/2.0.0/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
  from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
  from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
rake aborted!
No such file or directory - 

$ ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-linux]

$ gem env
RubyGems Environment:

  • RUBYGEMS VERSION: 2.0.3
  • RUBY VERSION: 2.0.0 (2013-05-14 patchlevel 195) [x86_64-linux]
  • INSTALLATION DIRECTORY: /home/vagrant/.gem/ruby/2.0.0
  • RUBY EXECUTABLE: /home/vagrant/.rubies/ruby-2.0.0-p195/bin/ruby
  • EXECUTABLE DIRECTORY: /home/vagrant/.gem/ruby/2.0.0/bin
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86_64-linux
  • GEM PATHS:
    • /home/vagrant/.gem/ruby/2.0.0
    • /home/vagrant/.rubies/ruby-2.0.0-p195/lib/ruby/gems/2.0.0
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :backtrace => false
    • :bulk_threshold => 1000
  • REMOTE SOURCES:

$ echo $PATH
Using ruby-2.0.0
/home/vagrant/.gem/ruby/2.0.0/bin:/home/vagrant/.rubies/ruby-2.0.0-p195/lib/ruby/gems/2.0.0/bin:/home/vagrant/.rubies/ruby-2.0.0-p195/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin

$ which ruby
/home/vagrant/.rubies/ruby-2.0.0-p195/bin/ruby

$ which rake
/home/vagrant/.gem/ruby/2.0.0/bin/rake

@indirect
Copy link
Member

Yes, Bundler is doing the version check and erroring. If you remove the ruby line from your Gemfie, you will notice (sooner or later) that you are actually running on Ruby 1.9. As is clearly demonstrated by the backtrace you just pasted again: /usr/lib/ruby/1.9.1/rubygems/custom_require.rb. Since we seem to have reached an impasse, I'm going to stop replying to this ticket now. You may want to investigate your rake, bundler, and gem executables to try to figure out how you're running rake and (I presume) bundle under 1.9 while running gem and ruby under 2.0.

@ichilton
Copy link
Author

Ok, thanks for at least replying this far.

@ichilton
Copy link
Author

Found the problem.... i'm shelling out to the heroku command in the rake task - which comes from Heroku Toolbelt.

However, at the top of /usr/bin/heroku is this shebang:

#!/usr/bin/env ruby1.9.1

and sure enough:

$ruby1.9.1 -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

So that makes sense - except why is bundler complaining? - where does bundler come in when a rake task is calling that executable?

What would you advise as the best fix? - I don't want to change /usr/bin/heroku as that's written by their toolbelt installer and will get upgraded from time to time.

Do I need to prefix the call in the rake task with something to send it through rbenv/bundler?

I'm just using backticks (heroku .....) to execute it at the moment.

Thanks,

Ian

@fnichol
Copy link
Contributor

fnichol commented May 31, 2013

For reference sake I suspect this issue is ENV['RUBYOPT'] being propagated to subprocesses that happen to be Ruby.

@indirect
Copy link
Member

As the docs mention, you need to use Bundler.with_clean_env{ foo } if foo is ruby and you don't want to apply the current bundle. But that won't change the ruby version.

On Fri, May 31, 2013 at 10:35 PM, Fletcher Nichol
notifications@github.com wrote:

For reference sake I suspect this issue is ENV['RUBYOPT'] being propagated to subprocesses that happen to be Ruby.

Reply to this email directly or view it on GitHub:
#2489 (comment)

@ichilton
Copy link
Author

Yep, that fixed it! :)

Changed the shell out to:
Bundler.with_clean_env { sh "cmd" }

Thanks guys.

@jess
Copy link

jess commented Jul 22, 2013

Just in case anyone else is searching this issue. I had the same problem using rvm. I was also running rake tasks and shelling out to heroku toolbelt and getting this error:

Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

The same fix worked for me, wrapping the shell commands with (example):

Bundler.with_clean_env {sh "heroku run bundle exec rake db:migrate --app #{app}"}

@henrik
Copy link
Contributor

henrik commented Jan 6, 2014

I, too, had this issue with rvm and shelling out to Heroku. This fixed it. @ichilton, thanks so much for getting to the bottom of it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants