2018-11-02 19:07:56 -04:00
|
|
|
BUNDLE-EXEC(1) BUNDLE-EXEC(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
NAME
|
|
|
|
bundle-exec - Execute a command in the context of the bundle
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
SYNOPSIS
|
|
|
|
bundle exec [--keep-file-descriptors] command
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
DESCRIPTION
|
2018-11-02 19:07:56 -04:00
|
|
|
This command executes the command, making all gems specified in the
|
2019-04-14 02:01:35 -04:00
|
|
|
[Gemfile(5)][Gemfile(5)] available to require in Ruby programs.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Essentially, if you would normally have run something like rspec
|
|
|
|
spec/my_spec.rb, and you want to use the gems specified in the [Gem-
|
|
|
|
file(5)][Gemfile(5)] and installed via bundle install(1) bun-
|
|
|
|
dle-install.1.html, you should run bundle exec rspec spec/my_spec.rb.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Note that bundle exec does not require that an executable is available
|
|
|
|
on your shell's $PATH.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
OPTIONS
|
|
|
|
--keep-file-descriptors
|
2018-11-02 19:07:56 -04:00
|
|
|
Exec in Ruby 2.0 began discarding non-standard file descriptors.
|
|
|
|
When this flag is passed, exec will revert to the 1.9 behaviour
|
|
|
|
of passing all file descriptors to the new process.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
BUNDLE INSTALL --BINSTUBS
|
|
|
|
If you use the --binstubs flag in bundle install(1) bun-
|
|
|
|
dle-install.1.html, Bundler will automatically create a directory
|
|
|
|
(which defaults to app_root/bin) containing all of the executables
|
|
|
|
available from gems in the bundle.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
After using --binstubs, bin/rspec spec/my_spec.rb is identical to bun-
|
|
|
|
dle exec rspec spec/my_spec.rb.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
ENVIRONMENT MODIFICATIONS
|
|
|
|
bundle exec makes a number of changes to the shell environment, then
|
2018-11-02 19:07:56 -04:00
|
|
|
executes the command you specify in full.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
o make sure that it's still possible to shell out to bundle from
|
|
|
|
inside a command invoked by bundle exec (using $BUNDLE_BIN_PATH)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
o put the directory containing executables (like rails, rspec,
|
|
|
|
rackup) for your bundle on $PATH
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
o make sure that if bundler is invoked in the subshell, it uses the
|
2019-04-14 02:01:35 -04:00
|
|
|
same Gemfile (by setting BUNDLE_GEMFILE)
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
o add -rbundler/setup to $RUBYOPT, which makes sure that Ruby pro-
|
2018-11-02 19:07:56 -04:00
|
|
|
grams invoked in the subshell can see the gems in the bundle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It also modifies Rubygems:
|
|
|
|
|
|
|
|
o disallow loading additional gems not in the bundle
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
o modify the gem method to be a no-op if a gem matching the require-
|
|
|
|
ments is in the bundle, and to raise a Gem::LoadError if it's not
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
o Define Gem.refresh to be a no-op, since the source index is always
|
2018-11-02 19:07:56 -04:00
|
|
|
frozen when using bundler, and to prevent gems from the system
|
|
|
|
leaking into the environment
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
o Override Gem.bin_path to use the gems in the bundle, making system
|
2018-11-02 19:07:56 -04:00
|
|
|
executables work
|
|
|
|
|
|
|
|
o Add all gems in the bundle into Gem.loaded_specs
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Finally, bundle exec also implicitly modifies Gemfile.lock if the lock-
|
2018-11-02 19:07:56 -04:00
|
|
|
file and the Gemfile do not match. Bundler needs the Gemfile to deter-
|
2019-04-14 02:01:35 -04:00
|
|
|
mine things such as a gem's groups, autorequire, and platforms, etc.,
|
2018-11-02 19:07:56 -04:00
|
|
|
and that information isn't stored in the lockfile. The Gemfile and
|
2019-04-14 02:01:35 -04:00
|
|
|
lockfile must be synced in order to bundle exec successfully, so bundle
|
|
|
|
exec updates the lockfile beforehand.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Loading
|
|
|
|
By default, when attempting to bundle exec to a file with a ruby she-
|
|
|
|
bang, Bundler will Kernel.load that file instead of using Kernel.exec.
|
2018-11-02 19:07:56 -04:00
|
|
|
For the vast majority of cases, this is a performance improvement. In a
|
2019-04-14 02:01:35 -04:00
|
|
|
rare few cases, this could cause some subtle side-effects (such as
|
|
|
|
dependence on the exact contents of $0 or __FILE__) and the optimiza-
|
|
|
|
tion can be disabled by enabling the disable_exec_load setting.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Shelling out
|
|
|
|
Any Ruby code that opens a subshell (like system, backticks, or %x{})
|
2018-11-02 19:07:56 -04:00
|
|
|
will automatically use the current Bundler environment. If you need to
|
|
|
|
shell out to a Ruby command that is not part of your current bundle,
|
2019-04-14 02:01:35 -04:00
|
|
|
use the with_clean_env method with a block. Any subshells created
|
|
|
|
inside the block will be given the environment present before Bundler
|
|
|
|
was activated. For example, Homebrew commands run Ruby, but don't work
|
|
|
|
inside a bundle:
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bundler.with_clean_env do
|
|
|
|
`brew install wget`
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Using with_clean_env is also necessary if you are shelling out to a
|
2018-11-02 19:07:56 -04:00
|
|
|
different bundle. Any Bundler commands run in a subshell will inherit
|
|
|
|
the current Gemfile, so commands that need to run in the context of a
|
2019-04-14 02:01:35 -04:00
|
|
|
different bundle also need to use with_clean_env.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bundler.with_clean_env do
|
|
|
|
Dir.chdir "/other/bundler/project" do
|
|
|
|
`bundle exec ./script`
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
Bundler provides convenience helpers that wrap system and exec, and
|
2018-11-02 19:07:56 -04:00
|
|
|
they can be used like this:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bundler.clean_system('brew install wget')
|
|
|
|
Bundler.clean_exec('brew install wget')
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
RUBYGEMS PLUGINS
|
2018-11-02 19:07:56 -04:00
|
|
|
At present, the Rubygems plugin system requires all files named
|
2019-04-14 02:01:35 -04:00
|
|
|
rubygems_plugin.rb on the load path of any installed gem when any Ruby
|
|
|
|
code requires rubygems.rb. This includes executables installed into the
|
|
|
|
system, like rails, rackup, and rspec.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
Since Rubygems plugins can contain arbitrary Ruby code, they commonly
|
|
|
|
end up activating themselves or their dependencies.
|
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
For instance, the gemcutter 0.5 gem depended on json_pure. If you had
|
|
|
|
that version of gemcutter installed (even if you also had a newer ver-
|
|
|
|
sion without this problem), Rubygems would activate gemcutter 0.5 and
|
|
|
|
json_pure <latest>.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-04-14 02:01:35 -04:00
|
|
|
If your Gemfile(5) also contained json_pure (or a gem with a dependency
|
|
|
|
on json_pure), the latest version on your system might conflict with
|
|
|
|
the version in your Gemfile(5), or the snapshot version in your Gem-
|
|
|
|
file.lock.
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
If this happens, bundler will say:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You have already activated json_pure 1.4.6 but your Gemfile
|
|
|
|
requires json_pure 1.4.3. Consider using bundle exec.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
In this situation, you almost certainly want to remove the underlying
|
|
|
|
gem with the problematic gem plugin. In general, the authors of these
|
2019-04-14 02:01:35 -04:00
|
|
|
plugins (in this case, the gemcutter gem) have released newer versions
|
2018-11-02 19:07:56 -04:00
|
|
|
that are more careful in their plugins.
|
|
|
|
|
|
|
|
You can find a list of all the gems containing gem plugins by running
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-18 02:28:08 -04:00
|
|
|
ruby -rrubygems -e "puts Gem.find_files('rubygems_plugin.rb')"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
At the very least, you should remove all but the newest version of each
|
2019-04-14 02:01:35 -04:00
|
|
|
gem plugin, and also remove all gem plugins that you aren't using (gem
|
|
|
|
uninstall gem_name).
|
2018-11-02 19:07:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
November 2019 BUNDLE-EXEC(1)
|