What's the Difference Between Bundle.Setup and Bundle.Require

what's the difference between bundle.setup and bundle.require

Bundler.setup modifies the LOAD_PATH, so you can do things like require 'some_gem' and they will work. It allows you to require gems 'by hand'. Before Bundler, using Rubygems, you would achieve much of the same effect doing require 'rubygems'.

Bundler.require(:default) on the other hand actually requires all the gems in the Gemfile (assuming you're not using groups; otherwise it requires those in the specified groups if you provide arguments). It is a shorthand for a bunch of require 'some_gem' statements.

See http://gembundler.com/rationale.html. Note that they say you have to do require 'bundler/setup' before doing Bundler.require, but in practice this usually is not necessary. I almost never use Bundler.setup (or require 'bundler/setup), because I require all gems via Bundler.require).

Bundler difference between setup and require?

Google can be your friend. Read this and this.

TL;DR Use Bundler.require instead of Bundler.setup

Are bundle exec and require 'bundler/setup' equivalent?

In your specific example they can be considered the same, however in reality they are not the same.

bundle exec makes some changes to the environment that bundler/setup does not make. If your foo.rb never runs a subshell, or never tries to run other ruby executables in subshells, then both versions are equivalent (they will both load bundled gems correctly and work exactly the same).

The whole idea with bundle exec is to enable you to run executables that were not originally designed with bundler in mind. Like rspec, rails, rackup. If your own app (foo.rb) does not try to run such executables that might be dependent on your bundles, then it makes no difference either way. Since all you want to make sure with bundler is that you load the correct gems, and for that bundler/setup works exactly as expected in your case.

From the bundler docs when talking about running ruby system executables:

In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.

However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.

Then from the manpage of bundle exec you can get some additional clues as to what bundle exec actually does:

ENVIRONMENT MODIFICATIONS

  • make sure that it's still possible to shell out to bundle from inside a command invoked by bundle exec (using $BUNDLE_BIN_PATH)
  • put the directory containing executables (like rails, rspec, rackup) for your bundle on $PATH
  • make sure that if bundler is invoked in the subshell, it uses the same Gemfile (by setting BUNDLE_GEMFILE)
  • add -rbundler/setup to $RUBYOPT, which makes sure that Ruby programs invoked in the subshell can see the gems in the bundle

So if you build your app with bundler support in mind, then you never need to bundle exec your app.

But if you need to use other tools that load your app code that might load gems before they load your app code (which then might pull in a wrong non-bundled gem), then you need to use bundle exec.

What are the difference between the gems bundle and bundler

If you look at the page for bundle, it's sort of poor man's alias. Someone realized that it will be a frequent mistake. Installing bundle simply installs bundler.

Good thing, imagine if someone actually created a completely separate gem, called bundle.

What is the difference between bundle and bundle update?

In a nutshell: bundle install handles changes to the Gemfile and
bundle update upgrades gems that are already managed by Bundler.

http://viget.com/extend/bundler-best-practices

Needless to say that bundle and bundle install are the same command, install is the default option for bundle.

Why do you need require 'bundler/setup' ?

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

Difference between $Bundle install and $Bundle update

bundle update and bundle install can both install the gems you specified in Gemfile but missing in gems.

But bundle update does one thing more to upgrade:

  1. If the gems specified in Gemfile don't have version, it will upgrade to whatever latest.
  2. If the gems specified in Gemfile have version controlled with ~>, it will upgrade to the latest at the final digit, the patch version.

    For example, if you have a gem in Gemfile

    'foo_gem', '~> 2.1.0'

    bundle update will check if newer version of 2.1.x is available in cloud. Say your current version is 2.1.2 and what's latest in cloud is 2.1.5, it will install 2.1.5. But if 2.2.6 is the newest, it won't do anything.

Better practice in my opinion

  1. Always add version to critical gems like rails.

  2. Stick to bundle install(or bundle which is default to install) in most cases. Only do bundle update when it's really necessary and you are fully prepared for the result.

Whats the difference between bundle install --deployment and bundle pack

Have a look at the description of the two on Bundler's site.

Running bundle install --deployment is to be run in the production environment, but will grab the gems from rubygems when run. Read more here under the 'Deploying Your Application' heading for the purpose of the --deployment flag.

bundle package is similar to the old rake rails:gems:freeze command from Rails 2.3. It grabs the gems and packages them in vendor/cache. From the bundler site here:

You can use this to avoid a dependency
on rubygems.org at deploy time, or if
you have private gems that are not in
a public repository

Difference between 'bundle' and 'bundle install' rails 3?

No. install is just the default option for the bundle command. Don't run either in your Gemfile, however, just specify the gem "fubar" there -- bundler knows how to read and process that file.



Related Topics



Leave a reply



Submit