Aug 5, 2011

Uninitialized constant Rake::DSL in Rails 3

Posted Aug 5, 2011

I got this error when I try to migrate a user model from Devise. The log says:
rake aborted!
uninitialized constant Rake::DSL
...[garbage logs]...

This problem is caused by an outdated Rake gem.   If you're rake version is less than 0.9.2 than you will experience this problem

To check Rake's version, execute this in the command line:
rake --version

You will say. But hey I just recently installed everything from Ruby to Rails gem. In my case, I got multiple installation of Rake, so I got 0.8.7 and 0.9.2 at the same time and my command line is using 0.8.7.

To be safe, I uninstalled all rake versions:
gem uninstall rake

If you have multiple versions of rake, it will ask you which version you'd like to uninstall

And install the latest again:
gem install rake

And voila! No more DSL problem when I execute
rake db:migrate

5 comments:

  1. thanks, Just what I need, really I didn't use 0.8.7.

    ReplyDelete
  2. Thank you so very very much! I googled this left and right and got all sorts of solutions, but this one is the only one I found that worked in my case. I just created a new rails app today and rake didn't work. Worked fine yesterday, and I hadn't updated anything. =)

    ReplyDelete
  3. Thanks, this worked like a charm!

    ReplyDelete
  4. Doesn't work for me...

    # gem install rake
    Successfully installed rake-0.9.2.2
    1 gem installed
    Installing ri documentation for rake-0.9.2.2...
    Installing RDoc documentation for rake-0.9.2.2...
    # rake generate_secret_token(in /var/www/***)
    rake aborted!
    uninitialized constant Rake::DSL
    /var/www/***/Rakefile:7
    (See full trace by running task with --trace)
    # rake --version
    rake, version 0.8.7

    I uninstalled it first. It didn't ask me for which version, it just removed 0.9.2.2. Then I installed it (0.9.2.2) again, but apparently version 0.8.7 is still installed and being used. Any idea?

    ReplyDelete
  5. In addition:

    # gem list -d rake

    *** LOCAL GEMS ***

    rake (0.9.2.2)
    Author: Jim Weirich
    Rubyforge: http://rubyforge.org/projects/rake
    Homepage: http://rake.rubyforge.org
    Installed at: /var/lib/gems/1.8

    Ruby based make-like utility.

    ReplyDelete