title: Rails uninitialized constant Bundler (NameError)
body: <p>I'm getting the following error when running any rails commands like <code>rails s</code> or <code>rails c</code>, it's also preventing my heroku app from starting (same error):</p>
  
  <pre><code>app/config/application.rb:7:in `&lt;top (required)&gt;': uninitialized constant Bundler (NameError)
  from /Users/you/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:126:in `require'
  </code></pre>
  
  <p>Line 7 in the error message is:</p>
  
  <pre><code>Bundler.require(:default, Rails.env)
  </code></pre>
  
  <p>Doing the commands as <code>bundle exec rails s</code> succeeds, but that doesn't help the heroku app. I've verified <code>which ruby</code>, <code>which rails</code> and <code>which bundler</code>. I've also tried starting a new rvm gemset and reinstalling the bundle. The heroku error is identical:</p>
  
  <pre><code> /app/config/application.rb:7:in `&lt;top (required)&gt;': uninitialized constant Bundler (NameError)
  </code></pre>
  
  <p>running <code>bundle check</code> returns no issues.</p>
  
  <p>Some similar questions suggested this:</p>
  
  <pre><code> bundle config --delete bin    # Turn off Bundler's stub generator
   rake rails:update:bin         # Use the new Rails 4 executables
   git add bin                   # Add bin/ to source control
  </code></pre>
  
  <p>But I tried it and got no changes. I'm on Rails 4</p>
  
  <p>edit:</p>
  
  <p>I was working in another app and ran <code>rails g model</code> and this popped up:</p>
  
  <pre><code>Bundler is using a binstub that was created for a different gem.
  This is deprecated, in future versions you may need to `bundle binstub rails` to work around a system/bundle conflict.
  </code></pre>
  
  <p>gemfile</p>
  
  <pre><code>source 'https://rubygems.org'
  ruby '2.0.0'
  gem 'rails', '4.0.3'
  gem 'sass-rails', '~&gt; 4.0.1'
  gem 'uglifier'
  gem 'coffee-rails'
  gem 'jquery-rails'
  gem 'turbolinks'
  gem 'jbuilder'
  gem 'bcrypt-ruby'
  gem "geocoder"
  gem 'gmaps4rails'
  gem "paperclip"
  gem 'route_translator'
  gem 'aws-sdk'
  gem 'ckeditor'
  gem 'soundcloud'
  gem 'omniauth-facebook'
  gem 'twitter'
  gem 'pg'
  gem 'unicorn'
  gem 'sass'
  gem 'compass', '0.12.2'
  gem 'font-awesome-rails'
  gem 'acts-as-taggable-on'
  gem 'json', '1.7.7'
  gem 'figaro'
  
  #for mailchimp api
  gem 'gibbon'
  
  #for deploying
  gem 'capistrano', '~&gt; 3.0.1'
  gem 'capistrano-rails', '~&gt; 1.1.0'
  gem 'capistrano-bundler'
  gem 'capistrano-rbenv', '~&gt; 2.0'
  gem 'exception_notification'
  gem 'textacular'
  gem 'mail_form'
  gem 'dumper'
  
  group :doc do
    gem 'sdoc', require: false
  end
  
  # development gems
  group :development, :test do
         # env variables
    gem "faker"
  end
  
  # Paging
  gem 'kaminari'
  gem 'will_paginate-bootstrap', '~&gt; 1.0.0'
  
  # Slugs and friendly id's
  gem 'friendly_id'
  
  # font-awesome
  gem 'font-awesome-sass', '~&gt; 4.0.2'
  
  # production gems for heroku
  group :production do
    gem 'rails_12factor'
    gem 'therubyracer'
    gem 'execjs'
  end
  
  
  # Devise
  gem 'devise'
  
  
  gem 'chosen-rails'
  
  
  # Bootstrap 3
  group :development, :test do
    gem 'rails_layout'  # Bootstrap 3 layout generator
  end
  
  gem 'bootstrap-sass', '~&gt; 3.0.3.0'   
  
  
  # RSpec
  group :test, :development do
    gem "rspec-rails"
    gem "factory_girl_rails"
  end
  
  # Capybara
  group :test do
    gem "capybara"
    gem 'email_spec'
  end
  </code></pre>
  
  <p>gemfile.lock</p>
  
  <p>GEM</p>
  
  <pre><code>  remote: https://rubygems.org/
    specs:
      actionmailer (4.0.3)
        actionpack (= 4.0.3)
        mail (~&gt; 2.5.4)
      actionpack (4.0.3)
        activesupport (= 4.0.3)
        builder (~&gt; 3.1.0)
        erubis (~&gt; 2.7.0)
        rack (~&gt; 1.5.2)
        rack-test (~&gt; 0.6.2)
      activemodel (4.0.3)
        activesupport (= 4.0.3)
        builder (~&gt; 3.1.0)
      activerecord (4.0.3)
        activemodel (= 4.0.3)
        activerecord-deprecated_finders (~&gt; 1.0.2)
        activesupport (= 4.0.3)
        arel (~&gt; 4.0.0)
      activerecord-deprecated_finders (1.0.3)
      activesupport (4.0.3)
        i18n (~&gt; 0.6, &gt;= 0.6.4)
        minitest (~&gt; 4.2)
        multi_json (~&gt; 1.3)
        thread_safe (~&gt; 0.1)
        tzinfo (~&gt; 0.3.37)
      acts-as-taggable-on (3.1.1)
        actionpack (&gt;= 3, &lt; 5)
        activerecord (&gt;= 3, &lt; 5)
        activesupport (&gt;= 3, &lt; 5)
      addressable (2.3.6)
      arel (4.0.2)
      aws-sdk (1.38.0)
        json (~&gt; 1.4)
        nokogiri (&gt;= 1.4.4)
        uuidtools (~&gt; 2.1)
      bcrypt (3.1.7)
      bcrypt-ruby (3.1.5)
        bcrypt (&gt;= 3.1.3)
      bootstrap-sass (3.0.3.0)
        sass (~&gt; 3.2)
      builder (3.1.4)
      capistrano (3.0.1)
        i18n
        rake (&gt;= 10.0.0)
        sshkit (&gt;= 0.0.23)
      capistrano-bundler (1.1.2)
        capistrano (~&gt; 3.0)
        sshkit (~&gt; 1.2)
      capistrano-rails (1.1.0)
        capistrano (&gt;= 3.0.0)
        capistrano-bundler (&gt;= 1.0.0)
      capistrano-rbenv (2.0.1)
        capistrano (~&gt; 3.0)
        sshkit (~&gt; 1.3)
      capybara (2.2.1)
        mime-types (&gt;= 1.16)
        nokogiri (&gt;= 1.3.3)
        rack (&gt;= 1.0.0)
        rack-test (&gt;= 0.5.4)
        xpath (~&gt; 2.0)
      chosen-rails (1.1.0)
        coffee-rails (&gt;= 3.2)
        compass-rails (&gt;= 1.1.2)
        railties (&gt;= 3.0)
        sass-rails (&gt;= 3.2)
      chunky_png (1.3.0)
      ckeditor (4.0.11)
        mime-types
        orm_adapter (~&gt; 0.5.0)
      climate_control (0.0.3)
        activesupport (&gt;= 3.0)
      cocaine (0.5.4)
        climate_control (&gt;= 0.0.3, &lt; 1.0)
      coffee-rails (4.0.1)
        coffee-script (&gt;= 2.2.0)
        railties (&gt;= 4.0.0, &lt; 5.0)
      coffee-script (2.2.0)
        coffee-script-source
        execjs
      coffee-script-source (1.7.0)
      compass (0.12.2)
        chunky_png (~&gt; 1.2)
        fssm (&gt;= 0.2.7)
        sass (~&gt; 3.1)
      compass-rails (1.1.7)
        compass (&gt;= 0.12.2)
        sprockets (&lt;= 2.11.0)
      devise (3.2.4)
        bcrypt (~&gt; 3.0)
        orm_adapter (~&gt; 0.1)
        railties (&gt;= 3.2.6, &lt; 5)
        thread_safe (~&gt; 0.1)
        warden (~&gt; 1.2.3)
      diff-lcs (1.2.5)
      dumper (1.5.0)
        multi_json (&gt;= 1.0)
        multipart-post (&gt;= 1.1.5)
        posix-spawn (&gt;= 0.3.6)
      email_spec (1.5.0)
        launchy (~&gt; 2.1)
        mail (~&gt; 2.2)
      erubis (2.7.0)
      exception_notification (4.0.1)
        actionmailer (&gt;= 3.0.4)
        activesupport (&gt;= 3.0.4)
      execjs (2.0.2)
      factory_girl (4.4.0)
        activesupport (&gt;= 3.0.0)
      factory_girl_rails (4.4.1)
        factory_girl (~&gt; 4.4.0)
        railties (&gt;= 3.0.0)
      faker (1.3.0)
        i18n (~&gt; 0.5)
      faraday (0.9.0)
        multipart-post (&gt;= 1.2, &lt; 3)
      figaro (0.7.0)
        bundler (~&gt; 1.0)
        rails (&gt;= 3, &lt; 5)
      font-awesome-rails (4.0.3.1)
        railties (&gt;= 3.2, &lt; 5.0)
      font-awesome-sass (4.0.3.1)
        sass (~&gt; 3.2)
      friendly_id (5.0.3)
        activerecord (&gt;= 4.0.0)
      fssm (0.2.10)
      geocoder (1.2.0)
      gibbon (1.1.2)
        httparty
        multi_json (&gt;= 1.3.4)
      gmaps4rails (2.1.2)
      hashie (2.1.1)
      hike (1.2.3)
      httmultiparty (0.3.14)
        httparty (&gt;= 0.7.3)
        mimemagic
        multipart-post
      httparty (0.11.0)
        multi_json (~&gt; 1.0)
        multi_xml (&gt;= 0.5.2)
      i18n (0.6.9)
      jbuilder (2.0.6)
        activesupport (&gt;= 3.0.0, &lt; 5)
        multi_json (~&gt; 1.2)
      jquery-rails (3.1.0)
        railties (&gt;= 3.0, &lt; 5.0)
        thor (&gt;= 0.14, &lt; 2.0)
      json (1.7.7)
      jwt (0.1.11)
        multi_json (&gt;= 1.5)
      kaminari (0.15.1)
        actionpack (&gt;= 3.0.0)
        activesupport (&gt;= 3.0.0)
      kgio (2.9.2)
      launchy (2.4.2)
        addressable (~&gt; 2.3)
      libv8 (3.16.14.3)
      mail (2.5.4)
        mime-types (~&gt; 1.16)
        treetop (~&gt; 1.4.8)
      mail_form (1.5.0)
        actionmailer (&gt;= 3.2, &lt; 5)
        activemodel (&gt;= 3.2, &lt; 5)
      mime-types (1.25.1)
      mimemagic (0.2.1)
      mini_portile (0.5.3)
      minitest (4.7.5)
      multi_json (1.9.2)
      multi_xml (0.5.5)
      multipart-post (2.0.0)
      net-scp (1.2.0)
        net-ssh (&gt;= 2.6.5)
      net-ssh (2.8.0)
      nokogiri (1.6.1)
        mini_portile (~&gt; 0.5.0)
      oauth2 (0.9.3)
        faraday (&gt;= 0.8, &lt; 0.10)
        jwt (~&gt; 0.1.8)
        multi_json (~&gt; 1.3)
        multi_xml (~&gt; 0.5)
        rack (~&gt; 1.2)
      omniauth (1.2.1)
        hashie (&gt;= 1.2, &lt; 3)
        rack (~&gt; 1.0)
      omniauth-facebook (1.6.0)
        omniauth-oauth2 (~&gt; 1.1)
      omniauth-oauth2 (1.1.2)
        faraday (&gt;= 0.8, &lt; 0.10)
        multi_json (~&gt; 1.3)
        oauth2 (~&gt; 0.9.3)
        omniauth (~&gt; 1.2)
      orm_adapter (0.5.0)
      paperclip (4.1.1)
        activemodel (&gt;= 3.0.0)
        activesupport (&gt;= 3.0.0)
        cocaine (~&gt; 0.5.3)
        mime-types
      pg (0.17.1)
      polyglot (0.3.4)
      posix-spawn (0.3.8)
      rack (1.5.2)
      rack-test (0.6.2)
        rack (&gt;= 1.0)
      rails (4.0.3)
        actionmailer (= 4.0.3)
        actionpack (= 4.0.3)
        activerecord (= 4.0.3)
        activesupport (= 4.0.3)
        bundler (&gt;= 1.3.0, &lt; 2.0)
        railties (= 4.0.3)
        sprockets-rails (~&gt; 2.0.0)
      rails_12factor (0.0.2)
        rails_serve_static_assets
        rails_stdout_logging
      rails_layout (1.0.14)
      rails_serve_static_assets (0.0.2)
      rails_stdout_logging (0.0.3)
      railties (4.0.3)
        actionpack (= 4.0.3)
        activesupport (= 4.0.3)
        rake (&gt;= 0.8.7)
        thor (&gt;= 0.18.1, &lt; 2.0)
      raindrops (0.13.0)
      rake (10.3.0)
      rdoc (3.12.2)
        json (~&gt; 1.4)
      ref (1.0.5)
      route_translator (3.2.0)
      rspec-core (2.14.8)
      rspec-expectations (2.14.5)
        diff-lcs (&gt;= 1.1.3, &lt; 2.0)
      rspec-mocks (2.14.6)
      rspec-rails (2.14.2)
        actionpack (&gt;= 3.0)
        activemodel (&gt;= 3.0)
        activesupport (&gt;= 3.0)
        railties (&gt;= 3.0)
        rspec-core (~&gt; 2.14.0)
        rspec-expectations (~&gt; 2.14.0)
        rspec-mocks (~&gt; 2.14.0)
      sass (3.2.19)
      sass-rails (4.0.3)
        railties (&gt;= 4.0.0, &lt; 5.0)
        sass (~&gt; 3.2.0)
        sprockets (~&gt; 2.8, &lt;= 2.11.0)
        sprockets-rails (~&gt; 2.0)
      sdoc (0.3.20)
        json (&gt;= 1.1.3)
        rdoc (~&gt; 3.10)
      simple_oauth (0.2.0)
      soundcloud (0.3.2)
        hashie (~&gt; 2.0)
        httmultiparty (~&gt; 0.3.0)
      sprockets (2.11.0)
        hike (~&gt; 1.2)
        multi_json (~&gt; 1.0)
        rack (~&gt; 1.0)
        tilt (~&gt; 1.1, != 1.3.0)
      sprockets-rails (2.0.1)
        actionpack (&gt;= 3.0)
        activesupport (&gt;= 3.0)
        sprockets (~&gt; 2.8)
      sshkit (1.4.0)
        net-scp (&gt;= 1.1.2)
        net-ssh (&gt;= 2.8.0)
        term-ansicolor
      term-ansicolor (1.3.0)
        tins (~&gt; 1.0)
      textacular (3.2.0)
        activerecord (&gt;= 3.0, &lt; 4.2)
      therubyracer (0.12.1)
        libv8 (~&gt; 3.16.14.0)
        ref
      thor (0.19.1)
      thread_safe (0.3.3)
      tilt (1.4.1)
      tins (1.1.0)
      treetop (1.4.15)
        polyglot
        polyglot (&gt;= 0.3.1)
      turbolinks (2.2.2)
        coffee-rails
      twitter (4.8.1)
        faraday (~&gt; 0.8, &lt; 0.10)
        multi_json (~&gt; 1.0)
        simple_oauth (~&gt; 0.2)
      tzinfo (0.3.39)
      uglifier (2.2.1)
        execjs (&gt;= 0.3.0)
        multi_json (~&gt; 1.0, &gt;= 1.0.2)
      unicorn (4.8.2)
        kgio (~&gt; 2.6)
        rack
        raindrops (~&gt; 0.7)
      uuidtools (2.1.4)
      warden (1.2.3)
        rack (&gt;= 1.0)
      will_paginate (3.0.5)
      will_paginate-bootstrap (1.0.0)
        will_paginate (&gt;= 3.0.3)
      xpath (2.0.0)
        nokogiri (~&gt; 1.3)
  
  PLATFORMS
    ruby
  
  DEPENDENCIES
    acts-as-taggable-on
    aws-sdk
    bcrypt-ruby
    bootstrap-sass (~&gt; 3.0.3.0)
    capistrano (~&gt; 3.0.1)
    capistrano-bundler
    capistrano-rails (~&gt; 1.1.0)
    capistrano-rbenv (~&gt; 2.0)
    capybara
    chosen-rails
    ckeditor
    coffee-rails
    compass (= 0.12.2)
    devise
    dumper
    email_spec
    exception_notification
    execjs
    factory_girl_rails
    faker
    figaro
    font-awesome-rails
    font-awesome-sass (~&gt; 4.0.2)
    friendly_id
    geocoder
    gibbon
    gmaps4rails
    jbuilder
    jquery-rails
    json (= 1.7.7)
    kaminari
    mail_form
    omniauth-facebook
    paperclip
    pg
    rails (= 4.0.3)
    rails_12factor
    rails_layout
    route_translator
    rspec-rails
    sass
    sass-rails (~&gt; 4.0.1)
    sdoc
    soundcloud
    textacular
    therubyracer
    turbolinks
    twitter
    uglifier
    unicorn
    will_paginate-bootstrap (~&gt; 1.0.0)
  </code></pre>
  
  <p>update2: If I clone the repo and <code>bundle install</code>, and the try to run <code>rails s</code> or any rake task, I replicate the <code>bundler</code> errors. However, if I then do <code>gem install bundler</code> and <code>gem install rake</code>, the new repo will work fine. Uninstalling and reinstalling the two gems in my original repo will not fix the issue. glad I've found a quasi fix, but would still like to get to the bottom of this.</p>
  
  <p>update3: I think I've narrowed it down to an issue with the gems, but not sure how to proceed. If I run the commands that trigger errors using my default gemset, there is no issue, it's only when I switch over to the gemset for this project that I get errors. I did not run <code>bundle update</code> before testing commands with the default gemset.</p>
  
  <p>update4: I've cloned the repo on another machine and it replicates the issue. So I'm guessing it's time to start going back and checking commits from before this issue and see what happens? My other idea is to start commenting out gems / removing dependencies and seeing if that helps. Anything else I might want to look at?</p>
  
  <p>After removing all gems, the warning with <code>uninitialized constant</code> is still present.</p>