Howto fix rake 0.9.2 to work with Ruby 1.9.2 under RVM

The recent version bump of rake seems to do no good for Ruby developer. And when combined with the monster Ruby 1.9.2, you can imagine you could pull your hair out trying to figure out why this or that doesn’t work. So if you happen to install Ruby 1.9.2 using RVM and bumped into below errors:

/Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:3: warning: already initialized constant NUMBERS /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/version.rb:9: warning: already initialized constant VERSION /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake.rb:26: warning: already initialized constant RAKEVERSION /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/early_time.rb:17: warning: already initialized constant EARLY /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:28: warning: already initialized constant DEFAULT_RAKEFILES WARNING: Possible conflict with Rake extension: String#ext already exists WARNING: Possible conflict with Rake extension: String#pathmap already exists /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/invocation_chain.rb:49: warning: already initialized constant EMPTY /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/dsl_definition.rb:143: warning: already initialized constant Commands /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:44: warning: already initialized constant ARRAY_METHODS /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:47: warning: already initialized constant MUST_DEFINE /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:51: warning: already initialized constant MUST_NOT_DEFINE /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:55: warning: already initialized constant SPECIAL_RETURN /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:61: warning: already initialized constant DELEGATING_METHODS /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:364: warning: already initialized constant DEFAULT_IGNORE_PATTERNS /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/file_list.rb:370: warning: already initialized constant DEFAULT_IGNORE_PROCS /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake.rb:64: warning: already initialized constant FileList /Users/devuser/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils rake aborted! stack level too deep

Here is how you could fix without reverting to version 0.8.7:

1. Please verify the rake installation with gem list | grep 'rake'. You will likely to see rake (0.9.2 ruby). I have no idea what ruby means, but it seems a duplication of rake that is installed @global.
2. Remove the duplicated version with gem uninstall rake. Please say Y for both 2 questions. Verify again with gem list | grep 'rake' and this time the output is rake (0.9.2). That’s it, this has fixed the issue. I speculate this is a bug with RVM.

Some people dislike 0.9.2 and wants to revert to 0.8.7 yet they could not do gem uninstall because rake is kept within no-touch @global zone. So here is how you can manually remove rake 0.9.2 from @global:

1. We need to figure out where rake resides with gem list -d rake. The output will likely be:

 
*** LOCAL GEMS ***

rake (0.9.2)
    Author: Jim Weirich
    Rubyforge: http://rubyforge.org/projects/rake
    Homepage: http://rake.rubyforge.org
    Installed at: /Users/mojo/.rvm/gems/ruby-1.9.2-p290@global

    Ruby based make-like utility.

2. The “Installed at” is the location, now we can remove it manually:

rm /Users/mojo/.rvm/gems/ruby-1.9.2-p290\@global/bin/rake
rm /Users/mojo/.rvm/gems/ruby-1.9.2-p290\@global/cache/rake-0.9.2.gem
rm -rf /Users/mojo/.rvm/gems/ruby-1.9.2-p290\@global/doc/rake-0.9.2/
rm -rf /Users/mojo/.rvm/gems/ruby-1.9.2-p290\@global/gems/rake-0.9.2/
rm /Users/mojo/.rvm/gems/ruby-1.9.2-p290\@global/specifications/rake-0.9.2.gemspec

3. Install rake 0.8.7 with gem install rake -v=0.8.7

Hope this helps.

About Jones Lee

Nothing much about me..

23 responses to “Howto fix rake 0.9.2 to work with Ruby 1.9.2 under RVM

  1. bobics

    Thanks, saved me (some) hair pulling.

  2. Thank you, thank you, thank you! This one had me scratching my head for a while too!

  3. Thank you very much for this, saved a massive headache! 🙂

  4. Worked splendidly! Thanks a bunch!

  5. Chris

    Thank you so much for writing this up! My coworkers and I were going crazy trying to find a solution to this. Everywhere else was talking about a bundle flag (bundle install –relock) that was removed. Your solution worked perfectly!

  6. Georgios

    Saved me many hours…!!! Thanks!

  7. Sam

    Thanks for the tip, this worked a treat!

  8. Thanks. This made a lot of sense.

  9. Ken Mitsui

    Thanks much, I was driven nut with this. Have you submitted this issue to RVM team?

  10. Thanks man! I was really starting to loose my patience with this problem. Didn’t have a clue about what was causing this. Thanks again!

  11. Ty! That solved the problem for me. Rails 3.1, Ruby 1.9.2 on Linux Mint.

  12. Adrian

    Or if you are using bundler, simply run “bundle exec rake” instead of “rake”, and it will load the correct version for you.

  13. Thanks Jones, Use ‘bundle exec’ is not as elegant as your solution.

  14. Thanks for your solution but when i uninstalled rake and try rake db:migrate
    got this
    Could not find rake-0.9.2 in any of the sources
    Try running `bundle install`

  15. thank you thank you this saved my life

  16. Emanuel

    Thank you very much! I’m very happy :). Muy buena información

  17. Pingback: Rake errors and RVM | Clever Molecule

  18. Stratos Pavlakis

    Really really thx! It just didn’t make sense 🙂

  19. Chandan Kumar

    Instead of removing file manually, you can do:
    $ rvm use @global
    $ gem uninstall rake

  20. ‘bundle’ is not recognized as an internal or external command,
    operable program or batch file.

    for windows

Leave a comment