3

Background:

  • I get errors whenever I run rake in an older project. (uninitialized constant Rake::DSL).
  • The rails project in question is an old project that was started with Rails 2.1 (I think), and since then I've updated the OS on my laptop a couple of times, and made updates along the way to make it run.
  • Right now, the rails app works fine, provided I have RAILS_GEM_VERSION set to 2.3.5. I'm not sure if the app was completely updated to Rails 2.3.5.
  • There is no Gemfile in my older project.
  • If I create a brand-new rails project (and unset RAILS_GEM_VERSION), rake runs fine.

My question: To troubleshoot, I'd like to try newer versions of rake. I'd like to know how to force one specific version to be used, since it appears I have multiple versions installed.

Info on my environment:

$ gem list rake

*** LOCAL GEMS ***

rake (0.9.2.2, 0.9.2, 0.8.7, 0.8.3)


$ rake --version
rake, version 0.8.7

So it looks like it's picking up the 0.8.7 version.

All the help files online seem to tell me to specify the rake version in the Gemfile, but there isn't one in this project. (Maybe it predates gemfiles?)

If I unset the RAILS_GEM_ENVIRONMENT variable altogether, and try to run rake, I get:

rake aborted!
can't activate rails (= 2.3.5, runtime) for [], already activated rails-3.2.8 for []

None of the environment config files in my older project set that variable either.

antun
  • 2,038
  • 2
  • 22
  • 34
  • 2
    http://stackoverflow.com/questions/6243304/use-older-version-of-rake This may be of help. Have you tried the underscore solution? – John Sep 26 '12 at 07:52
  • I just tried the underscore solution, but when I do: $ rake \_0.9.2\_ --version, it still says that it's using 0.8.7. – antun Sep 26 '12 at 13:37
  • I did a little digging, and I thing I understand why the underscore method doesn't work for me. Apparently, for executable gems (like rake) there should be a wrapper that calls it in the path. However, for me, /usr/bin/rake is a symlink to ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/rake . That's *not* the same as my rails executable. For me, /usr/bin/rails is a shell script that extracts the version from the command line. Can you cat your /usr/bin/rake file? – antun Sep 27 '12 at 00:08
  • I just ran gem pristine rake, and that restored /usr/bin/rake to a shell script wrapper. Not only that, but my errors are gone. – antun Sep 27 '12 at 00:11
  • Great to hear that you got it working. – John Sep 27 '12 at 04:03
  • Do you want to post your original anaswer as a question, so I can accept it? – antun Sep 27 '12 at 16:56

3 Answers3

9

This may be of help. Have you tried the underscore solution?

Example:

rake _0.9.2_
Community
  • 1
  • 1
John
  • 4,362
  • 5
  • 32
  • 50
  • This is the correct answer, but in my case my environment was a little messed-up. (See comments above about using gem pristine rake to correct it). – antun Sep 28 '12 at 17:19
2

you can run rake specific version by using this

bundle exec rake ...

more detail see this - bundle exec, rake

Dipak Panchal
  • 5,996
  • 4
  • 32
  • 68
  • 1
    The docs for bundle-exec say that it uses what's specified in the Gemfile. But my project doesn't have a Gemfile. I'm not sure why it doesn't; maybe because it is based on a Rails version that predates that. – antun Sep 26 '12 at 13:35
1

You can uninstall the current version of rake and install another desired version using commands similar to the following:

gem uninstall rake 12.3.1
gem install rake 10.5.0

(Note: you might need to run as sudo for permissions)

I had a problem where I received the following error while trying to install rake 10.5.0:

Could not find a valid gem '0.8.7' (>= 0) in any repository

I resolved this problem by adding the following line to my Gemfile:

gem 'rake', ' <11.0'

After editing Gemfile I was able to successfully downgrade rake by updating my gems:

bundle update
Kmeixner
  • 1,664
  • 4
  • 22
  • 32