25

I'm trying to run Rails 3 beta 4 & Ruby 1.9.2rc on Ubuntu 10.04. It worked initially, but after doing my first bundle install/package, I now get the following errors in all rails projects. Even a basic 'rails new testproject' followed by a rake brings up the error messages.

In short, I'm stumped. Any help regarding what could be causing this would be very appreciated.

The only thing I noticed - which may or may not be relevant - is that the directory in the ~/.bundle files is ruby/1.9.1. 1.9.1 is not installed on my machine - only 1.9.2rc. ruby -v brings back 1.9.2

(in /home/john/Websites/sandbox/testerino)
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:32: warning: already initialized constant RAKEVERSION
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake/alt_system.rb:32: warning: already initialized constant WINDOWS
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:404: warning: already initialized constant EMPTY_TASK_ARGS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:452: warning: already initialized constant EMPTY
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:960: warning: already initialized constant RUBY_EXT
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:964: warning: already initialized constant RUBY
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1033: warning: already initialized constant LN_SUPPORTED
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1242: warning: already initialized constant ARRAY_METHODS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1245: warning: already initialized constant MUST_DEFINE
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1249: warning: already initialized constant MUST_NOT_DEFINE
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1253: warning: already initialized constant SPECIAL_RETURN
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1259: warning: already initialized constant DELEGATING_METHODS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1569: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1575: warning: already initialized constant DEFAULT_IGNORE_PROCS
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1612: warning: already initialized constant FileList
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1638: warning: already initialized constant EARLY
/home/john/.bundle/ruby/1.9.1/gems/rake-0.8.7/lib/rake.rb:1968: warning: already initialized constant DEFAULT_RAKEFILES
rake aborted!
stack level too deep
PlankTon
  • 12,443
  • 16
  • 84
  • 153

13 Answers13

31

I've been running into this issue too. It doesn't seem to be related to the specific versions of rails or ruby you mention, which are different than the ones I'm using (Rails 2.3.8, Rake 0.8.7, Ruby 1.9.1p378). It seems to be related to bundler and rake not working well together.

A resolution that worked for me is mentioned at the bottom of this lighthouse ticket. Here is the short version:

  • Run "bundle exec bash"; see if rake works now - if it does,
  • Make sure that the bash environments, before and after, are the same by consulting the env command and modifying ~/.bashrc or ~/.bash_profile accordingly.

Once you do this, you mess up bundler a little bit. At that point you have to clear RUBYOPT in order to run the bundle command:

RUBYOPT= bundle install --relock

EDIT:

Thinking about it a little more, I'm not sure this is necessarily the best way to address this particular issue. You might give Hiral Desai's tip and some other answers a try before resorting to this approach, since this one changes the environment.

Eric Walker
  • 7,063
  • 3
  • 35
  • 38
  • 1
    I had a similar issue executing any rake task in my Rails app. It went away after running `bundle exec bash`, but I have to re-run `bundle exec bash` if I open a new tab in my terminal. – ravinggenius May 17 '11 at 19:10
24

I'm afraid the easier solution is running this command instead of rake db:migrate

bundle exec rake db:migrate
Hiral Desai
  • 1,062
  • 1
  • 9
  • 24
  • Yeah - that might actually be better, since your environment isn't modified. – Eric Walker Aug 24 '11 at 15:42
  • 1
    It was suggested by a friend of mine, Pratik Naik (http://stackoverflow.com/users/639946/pratik-naik) who also happens to be in rails core team. Don't -1 my post because of that, I was just spreading knowledge. :) – Hiral Desai Aug 24 '11 at 16:32
4

As per the previous message from Eric W. the RUBYOPT environment variable is set. If you want to exit the new bash shell that is opened by "bundle exec bash" then just copy the RUBYOPT environment line, exit the shell then type "export RUBYOPT='THE ARGS THAT YOU COPIED FROM THE PREVIOUS ENVIRONMENT'

Note: this works with ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0] , Rails 3.0.7, gem 1.8.0 and Rake 0.8.7

cramhead
  • 1,057
  • 8
  • 21
4

bundle exec bash works for me

Richard Zhang
  • 350
  • 1
  • 4
3

I was able to solve this issue by downgrading my rubygem install from 1.8.10 to 1.7.2.

gem update --system 1.7.2
Kyle Mathews
  • 121
  • 1
  • 4
1

Looks like a strange recursive require.

Did you try uninstalling all versions of rake and reinstalling it? There is a bug in 1.9.2rc affecting gem loading, so that might be it? I didn't look closely into it as many people are already following it closely...

Note: The 1.9.1 is the API version, so it is correct.

Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
0

This can happen when you have the rake gem installed in both your repo's rvm gemset and the global one.

jeremiemv
  • 138
  • 5
0

Update to latest Rails minor version. So if you are at 4.2, update => 4.2.latest.

Karlo Smid
  • 525
  • 1
  • 5
  • 13
0

I had a .bundler folder on my root directory which was conflicting. Removing it did it for me.

rm -rf ~/.bundler
abbraga
  • 71
  • 5
0

I've been running into this issue too after updating rubygem (1.8.10) and bundler (1.0.18)

I solved updating rake to 0.9.2

vicvega
  • 2,249
  • 1
  • 15
  • 13
0

Just got such error because of deleted .rvmrc

So please make sure you running rake in correct environment ;)

A B
  • 2,013
  • 2
  • 21
  • 22
0

If you have RVM installed, this issue can start to occur once you update rubygems to 1.8.15. The issue was that I had rake installed in the global gemset and my project's gemset. The solution was to have only one installation of rake. To delete it from the project gemset: 1. cd to the project 2. gem uninstall rake

Liron Yahdav
  • 10,152
  • 8
  • 68
  • 104
0

Another possible solution is given at http://rubyist-journal.com/2011/07/29/howto-fix-rake-0-9-2-to-work-with-ruby-1-9-2-under-rvm/

It seems to boil down to having the same rake gem installed both in your user gem directory and system-wide. Removing either one fixes the issue.