Why do you need "require 'bundler/setup'"?

Martin picture Martin · Aug 30, 2011 · Viewed 13.9k times · Source

In almost every Sinatra example I've seen, despite what it does, it always has the following two lines:

require 'rubygems'
require 'bundler/setup'

In most examples, removing the 'bundler/setup' require seems to have no breaking effect, so I'm confused about when/where I need to include this.

I hate using things without knowing exactly the reason for it being there, so I was hoping someone could explain why I need both lines and what they do?

Answer

lucapette picture lucapette · Aug 30, 2011

It ensures you're loading Gemfile defined gems. Please have a look at the documentation here https://bundler.io/v1.12/bundler_setup.html