11

When I run rake db:create:all, I’m getting the following message:

/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/version.rb:5: warning: already initialized constant MINOR
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/version.rb:6: warning: already initialized constant BUILD
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/version.rb:3: warning: already initialized constant NUMBERS
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/version.rb:9: warning: already initialized constant VERSION
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake.rb:26: warning: already initialized constant RAKEVERSION
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/early_time.rb:17: warning: already initialized constant EARLY
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/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/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/invocation_chain.rb:49: warning: already initialized constant EMPTY
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/dsl_definition.rb:143: warning: already initialized constant Commands
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_list.rb:44: warning: already initialized constant ARRAY_METHODS
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_list.rb:47: warning: already initialized constant MUST_DEFINE
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_list.rb:51: warning: already initialized constant MUST_NOT_DEFINE
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_list.rb:55: warning: already initialized constant SPECIAL_RETURN
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_list.rb:61: warning: already initialized constant DELEGATING_METHODS
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_list.rb:364: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_list.rb:370: warning: already initialized constant DEFAULT_IGNORE_PROCS
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake.rb:64: warning: already initialized constant FileList
/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake.rb:65: warning: already initialized constant RakeFileUtils
rake aborted!
stack level too deep

And the database is not created. Can someone help me?

Ry-
  • 218,210
  • 55
  • 464
  • 476
user930538
  • 111
  • 1
  • 3

4 Answers4

25

I found a hint on the internet how to avoid the error. See the link to "Rail 3.1 and Rake aborted". There is given no reason, but to use bundle exec rake instead of the pure rake call has done the trick there. Seems like the call for rake is calling itself recursively, without having noticed that the files are yet loaded.

So give it a try and tell us if that worked for you.

mliebelt
  • 15,345
  • 7
  • 55
  • 92
  • 1
    Yes, the usual source of rake problems is forgetting to call it by `bundle exec`. For the ones who usually forget about things, calling a `bundle exec bash` would help. – Arsen7 Sep 06 '11 at 11:54
  • This helped. Only got this in rake 12.3.0 after upgrading from 10.4.2 but prepending with bundle exec rake no longer throws out warnings compared to rake – octoquad Nov 29 '17 at 11:03
19

If, like me, you are too lazy to use bundle every time:

Want to see a magic trick? Try running gem uninstall rake. Confirm when asked about broken dependencies. Counter-intuitive, I know.

Now run your rake command without bundle exec. Magic!

I don't know how it really works, but I'm thinking it has something to do with your local/global gemsets; your rvm global rake should be the one being used now.

No, this may not good practice, but like I said, it's for the lazy.

Jonathan Allard
  • 18,429
  • 11
  • 54
  • 75
  • 1
    This worked for me, I wonder if it has anything to do with having had older versions of Rails installed. – Denny Ferrassoli Oct 03 '11 at 02:30
  • ...Just to add that I got the same problem by using Rails 3.1.1 on a laptop where I had an older version of rails too. @jonallard tip solved the problem. – microspino Oct 10 '11 at 18:00
  • Worked for me **after** restarting the terminal. :) – talyric Jul 26 '12 at 22:09
  • 1
    I wonder what 'which rake' would yield before and after this fix – Perry Horwich Nov 03 '12 at 21:33
  • Very cool... I ended up with this informative output when I uninstalled: `$ gem uninstall rake ERROR: While executing gem ... (Gem::InstallError) rake is not installed in GEM_HOME, try: gem uninstall -i /Users/jon/.rvm/gems/ruby-2.1.5@global rake` Following the advice, I uninstalled the global rake, and then local rake just worked without error. – Jon Kern Mar 25 '15 at 02:32
  • @JonKern this is the error I get as well. Might be a later ruby/rake veresion – PandaWood Dec 14 '16 at 06:19
3

I've found another way to do not have to run bundle exec every time. For myself, working w/ Sinatra (not Rails), adding gem 'rake' to my Gemfile worked like a charm. :)

Pedro Romano
  • 10,973
  • 4
  • 46
  • 50
mcsgad
  • 31
  • 1
0

Command gem uninstall rake showes me that I have multiple rake gems installed, after removing 2 out of 3 I don't need to use bundle exec any more!