简体   繁体   中英

Rails3 server and bundler error: uninitialized constant Bundler (NameError)

I just install rails 3 and all gems that it need, but when I try to start server, it says about problem in boot script.

[rap-kasta@acerAspire testR3]$ script/rails server  
/home/rap-kasta/tmp/testR3/config/boot.rb:7:in `rescue in <top (required)>': uninitialized constant Bundler (NameError)  
        from /home/rap-kasta/tmp/testR3/config/boot.rb:2:in `<top (required)>'  
        from script/rails:9:in `require'  
        from script/rails:9:in `<main>  

So, I tried to reinstall Bundler, install "pre"-version (but really it has version number lower then i install by gem install bundler

Now there are next gems in system:

abstract (1.0.0)
actionmailer (3.0.0.beta, 2.3.5, 2.3.4)
actionpack (3.0.0.beta, 2.3.5, 2.3.4)
activemodel (3.0.0.beta)
activerecord (3.0.0.beta, 2.3.5, 2.3.4)
activeresource (3.0.0.beta, 2.3.5, 2.3.4)
activesupport (3.0.0.beta, 2.3.5, 2.3.4)
arel (0.2.1, 0.2.pre)
builder (2.1.2)
bundler (0.9.5)
erubis (2.6.5)
fxri (0.3.7)
fxruby (1.6.20)
i18n (0.3.3)
jemini (2010.1.24, 2010.1.5)
mail (2.1.2)
memcache-client (1.7.8)
mime-types (1.16)
mysql (2.8.1)
nifty-generators (0.3.2, 0.3.0)
rack (1.1.0, 1.0.1, 1.0.0)
rack-mount (0.5.1, 0.4.0)
rack-openid (0.2.3, 0.2.2)
rack-test (0.5.3)
rails (3.0.0.beta, 2.3.5, 2.3.4)
railties (3.0.0.beta)
rake (0.8.7)
rawr (1.3.8)
RedCloth (4.2.2)
ruby-mysql (3.0.2)
ruby-openid (2.1.7)
rubygems-update (1.3.5)
rubyzip (0.9.4, 0.9.1)
rubyzip2 (2.0.1)
sqlite3-ruby (1.2.5)
text-format (1.0.0)
text-hyphen (1.0.0)
thor (0.13.2, 0.13.1)
tzinfo (0.3.16)

Also, there is same error with rails console and similar with bundle check :

[rap-kasta@acerAspire testR3]$ bundle check
/usr/lib/ruby/gems/1.9.1/gems/bundler-0.9.5/bin/bundle:12:in `rescue in <top (required)>': uninitialized constant Bundler::BundlerError (NameError)
        from /usr/lib/ruby/gems/1.9.1/gems/bundler-0.9.5/bin/bundle:10:in `<top (required)>'
        from /usr/bin/bundle:19:in `load'
        from /usr/bin/bundle:19:in `<main>'

it works after adding:

gem install bundler

and after adding:

gem 'bundler'

in line 2 in config/boot.rb (just after require 'rubygems')

Please confirm paths of ruby and rake command.

$ which ruby
/usr/bin/ruby
$ which rake
/usr/local/bin/rake

I got the same error. In my case, I installed Rails with /usr/bin/ruby, but rake uses /usr/local/bin/ruby. This is why I got the error related to Bundler.

It isn't a bug in Bundler (or Rails), It's a bug (?!) in gems system, I think... So.. I also have gem 'rawr', which have file 'bundler.rb' and gems system load it instead of 'bundler/../bundler.rb'.

I removed rawr, but now I can't use jemini... But my problem closed now.

I had upgraded my rubygems to 1.5.0 but I needed to also put ruby-1.9.2-p180 as my default ruby version in RVM. This did the trick for me.

I had the problem on Mac, because several gems (including bundler) were installed in "/opt/local/lib/ruby/gems/1.8", which is loaded by default by RubyGems in irb, but not in rake.

Here is how I fixed it, it is probably not perfect, but at least it works:

  1. Find the path(s) you need by going in irb and doing

     require 'rubygems' Gem.path => ["/Users/joel/.gem/ruby/1.8", "/opt/local/lib/ruby/gems/1.8"] 

    These are the default paths, so if everything works for you in irb they're good.

  2. Now, in boot.rb , add (use your paths if they differ of course)

     Gem.path.push "/opt/local/lib/ruby/gems/1.8" Gem::Specification.find_by_name('bundler').activate 

    Right after

     require 'rubygems' 

Hope this solves it for you, at least I'm glad I fixed it for me so I can finally use Rails 3 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM