Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

bundler

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?

like image 378
Martin Avatar asked Aug 30 '11 12:08

Martin


People also ask

What does require bundler setup do?

Bundler. setup only sets up the load paths so that you can require your dependencies when and wherever you like. Bundler. require sets up the load paths and automatically requires every dependency, saving you from having to manually require each one.

Why is bundle exec needed?

bundle exec allows us to run an executable script in the specific context of the project's bundle. Upon running the above command, bundle exec will run the executable script for rake version specified in project's Gemfile thus avoiding any conflicts with other versions of rake installed system-wide.

How does bundler work in Rails?

Think of bundler as a package management tool. So bundle install command will install all gems to the system that are listed in Gemfile as well as their dependencies. If the gem was not previously installed it will grab it from the gemcutter repo.


1 Answers

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

like image 180
lucapette Avatar answered Sep 29 '22 18:09

lucapette