Search code examples
rubybundler

Difference between 'require bundler' and 'require bundler/setup'


When I use

require 'bundler/setup' 

i get Bundler.with_clean_env is not supported.

But when I change this to

require 'bundler' 

It supports Bundler.with_clean_env. The confusion that rises here is what is the difference between requiring 'bundler' and 'bundler/setup'?


Solution

  • When referring to gems, require 'foo' would require the foo.rb file that is located in the gem's lib directory. That file usually has the same name as the gem and is responsible for requiring all other necessary files for the gem to function.

    When you do require 'foo/bar', you search for lib/foo/bar.rb. In other words, you require only a specific file from that gem and not the whole thing.


    The bundler/setup is responsible for loading all gems described in your Gemfile. Bundler.with_clean_env is a completely different functionality, defined in the gem's main file.