This repository was archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbundle_exec.html
430 lines (371 loc) · 14.5 KB
/
bundle_exec.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta content='IE=edge' http-equiv='X-UA-Compatible'>
<meta content='en' http-equiv='Content-Language'>
<meta content='width=device-width, initial-scale=1' name='viewport'>
<meta content='276VSYOko8B8vIu1i8i5qbj7_ql5PXo0dU69XQy-SL' name='globalsign-domain-verification'>
<title>
Bundler: bundle exec
</title>
<link href='/bundle_exec.html' rel='canonical'>
<script src="/application.min.js"></script>
<link href="/application.css" rel="stylesheet" />
<link href='/images/apple-touch-icon.png' rel='apple-touch-icon' sizes='180x180'>
<link href='/images/favicon-32x32.png' rel='icon' sizes='32x32' type='image/png'>
<link href='/images/favicon-16x16.png' rel='icon' sizes='16x16' type='image/png'>
<link href='/manifest.json' rel='manifest'>
<link color='#50bced' href='/images/safari-pinned-tab.svg' rel='mask-icon'>
<meta content='bundler.io' name='apple-mobile-web-app-title'>
<meta content='bundler.io' name='application-name'>
<meta content='#ffffff' name='theme-color'>
<link rel="alternate" type="application/atom+xml" title="Atom Feed" href="/blog/feed.xml" />
</head>
<body class=''>
<nav class='navbar navbar-expand-md navbar-light'>
<div class='container-md'>
<a href="/" class="navbar-brand me-auto fw-bold">Bundler</a>
<button aria-controls='bs-navbar-collapse' aria-expanded='false' aria-label='Toggle navigation' class='navbar-toggler' data-bs-target='#bs-navbar-collapse' data-bs-toggle='collapse' type='button'>
<span class='navbar-toggler-icon'></span>
</button>
<div class='collapse navbar-collapse flex-grow-0' id='bs-navbar-collapse'>
<ul class='navbar-nav'>
<li class='nav-item'>
<input class='input-search my-1 ps-1 pt-1' id='input-search' placeholder='Type to search...' type='text'>
<svg class='text-opacity-40 m-1 mb-2' style='width: 1rem; height: 1rem; fill: currentcolor;' viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'>
<!-- Font Awesome Free 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. -->
<path d='M500.3 443.7l-119.7-119.7c27.22-40.41 40.65-90.9 33.46-144.7C401.8 87.79 326.8 13.32 235.2 1.723C99.01-15.51-15.51 99.01 1.724 235.2c11.6 91.64 86.08 166.7 177.6 178.9c53.8 7.189 104.3-6.236 144.7-33.46l119.7 119.7c15.62 15.62 40.95 15.62 56.57 0C515.9 484.7 515.9 459.3 500.3 443.7zM79.1 208c0-70.58 57.42-128 128-128s128 57.42 128 128c0 70.58-57.42 128-128 128S79.1 278.6 79.1 208z'></path>
</svg>
</li>
<li class='nav-item'><a href="/docs.html" class="nav-link">Docs</a></li>
<li class='nav-item'><a href="/contributors.html" class="nav-link">Team</a></li>
<li class='nav-item'><a href="/blog" class="nav-link">Blog</a></li>
<li class='nav-item'><a href="https://github.com/rubygems/rubygems/tree/master/bundler" target="_blank" rel="noopener noreferrer" class="nav-link">Repository</a></li>
</ul>
</div>
</div>
</nav>
<div class='bg-light-blue header'>
<img src="/images/docs_header_transparent_bg.png" srcset="/images/docs_header_transparent_bg.png 1x, /images/[email protected] 2x, /images/[email protected] 3x" class="img-fluid header-padding" style="max-width: 400px;" alt="" />
</div>
<div class='container'>
<div class='row flex-column flex-md-row-reverse'>
<div class='col-12 col-md-9 contents commands' id='page-content-wrapper'>
<div class="mp" id="man">
<h2 id="NAME">bundle exec</h2>
<p class="man-name">
<code>bundle-exec</code> - <span class="man-whatis">Execute a command in the context of the bundle</span>
</p>
<pre><code>bundle exec</code> [--keep-file-descriptors] <var>command</var></pre>
<h2 id="DESCRIPTION">Description</h2>
<p>This command executes the command, making all gems specified in the
<code>Gemfile(5)</code> available to <code>require</code> in Ruby programs.</p>
<p>Essentially, if you would normally have run something like
<code>rspec spec/my_spec.rb</code>, and you want to use the gems specified
in the <code>Gemfile(5)</code> and installed via <a href="bundle-install.1.html">bundle install(1)</a>, you
should run <code>bundle exec rspec spec/my_spec.rb</code>.</p>
<p>Note that <code>bundle exec</code> does not require that an executable is
available on your shell's <code>$PATH</code>.</p>
<h2 id="OPTIONS">Options</h2>
<dl>
<dt><code>--keep-file-descriptors</code></dt>
<dd>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.</dd>
</dl>
<h2 id="BUNDLE-INSTALL-BINSTUBS">Bundle Install --binstubs</h2>
<p>If you use the <code>--binstubs</code> flag in <a href="bundle-install.1.html">bundle install(1)</a>, Bundler will
automatically create a directory (which defaults to <code>app_root/bin</code>)
containing all of the executables available from gems in the bundle.</p>
<p>After using <code>--binstubs</code>, <code>bin/rspec spec/my_spec.rb</code> is identical
to <code>bundle exec rspec spec/my_spec.rb</code>.</p>
<h2 id="ENVIRONMENT-MODIFICATIONS">Environment Modifications</h2>
<p><code>bundle exec</code> makes a number of changes to the shell environment,
then executes the command you specify in full.</p>
<ul>
<li>make sure that it's still possible to shell out to <code>bundle</code>
from inside a command invoked by <code>bundle exec</code> (using
<code>$BUNDLE_BIN_PATH</code>)</li>
<li>put the directory containing executables (like <code>rails</code>, <code>rspec</code>,
<code>rackup</code>) for your bundle on <code>$PATH</code>
</li>
<li>make sure that if bundler is invoked in the subshell, it uses
the same <code>Gemfile</code> (by setting <code>BUNDLE_GEMFILE</code>)</li>
<li>add <code>-rbundler/setup</code> to <code>$RUBYOPT</code>, which makes sure that
Ruby programs invoked in the subshell can see the gems in
the bundle</li>
</ul>
<p>It also modifies Rubygems:</p>
<ul>
<li>disallow loading additional gems not in the bundle</li>
<li>modify the <code>gem</code> method to be a no-op if a gem matching
the requirements is in the bundle, and to raise a
<code>Gem::LoadError</code> if it's not</li>
<li>Define <code>Gem.refresh</code> to be a no-op, since the source
index is always frozen when using bundler, and to
prevent gems from the system leaking into the environment</li>
<li>Override <code>Gem.bin_path</code> to use the gems in the bundle,
making system executables work</li>
<li>Add all gems in the bundle into Gem.loaded_specs</li>
</ul>
<h3 id="Loading">Loading</h3>
<p>By default, when attempting to <code>bundle exec</code> to a file with a ruby shebang,
Bundler will <code>Kernel.load</code> that file instead of using <code>Kernel.exec</code>. For the
vast majority of cases, this is a performance improvement. In a rare few cases,
this could cause some subtle side-effects (such as dependence on the exact
contents of <code>$0</code> or <code>__FILE__</code>) and the optimization can be disabled by enabling
the <code>disable_exec_load</code> setting.</p>
<h3 id="Shelling-out">Shelling Out</h3>
<p>Any Ruby code that opens a subshell (like <code>system</code>, backticks, or <code>%x{}</code>) 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, use the
<code>with_clean_env</code> 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:</p>
<pre><code>Bundler.with_clean_env do
 `brew install wget`
end
</code></pre>
<p>Using <code>with_clean_env</code> is also necessary if you are shelling out to a 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 different bundle also
need to use <code>with_clean_env</code>.</p>
<pre><code>Bundler.with_clean_env do
 Dir.chdir "/other/bundler/project" do
 `bundle exec ./script`
 end
end
</code></pre>
<p>Bundler provides convenience helpers that wrap <code>system</code> and <code>exec</code>, and they
can be used like this:</p>
<pre><code>Bundler.clean_system('brew install wget')
Bundler.clean_exec('brew install wget')
</code></pre>
<h2 id="RUBYGEMS-PLUGINS">Rubygems Plugins</h2>
<p>At present, the Rubygems plugin system requires all files
named <code>rubygems_plugin.rb</code> on the load path of <em>any</em> installed
gem when any Ruby code requires <code>rubygems.rb</code>. This includes
executables installed into the system, like <code>rails</code>, <code>rackup</code>,
and <code>rspec</code>.</p>
<p>Since Rubygems plugins can contain arbitrary Ruby code, they
commonly end up activating themselves or their dependencies.</p>
<p>For instance, the <code>gemcutter 0.5</code> gem depended on <code>json_pure</code>.
If you had that version of gemcutter installed (even if
you <em>also</em> had a newer version without this problem), Rubygems
would activate <code>gemcutter 0.5</code> and <code>json_pure <latest></code>.</p>
<p>If your <a class="man-ref" href="gemfile.5.html">Gemfile<span class="s">(5)</span></a> also contained <code>json_pure</code> (or a gem
with a dependency on <code>json_pure</code>), the latest version on
your system might conflict with the version in your
<a class="man-ref" href="gemfile.5.html">Gemfile<span class="s">(5)</span></a>, or the snapshot version in your <code>Gemfile.lock</code>.</p>
<p>If this happens, bundler will say:</p>
<pre><code>You have already activated json_pure 1.4.6 but your Gemfile
requires json_pure 1.4.3. Consider using bundle exec.
</code></pre>
<p>In this situation, you almost certainly want to remove the
underlying gem with the problematic gem plugin. In general,
the authors of these plugins (in this case, the <code>gemcutter</code>
gem) have released newer versions that are more careful in
their plugins.</p>
<p>You can find a list of all the gems containing gem plugins
by running</p>
<pre><code>ruby -rubygems -e "puts Gem.find_files('rubygems_plugin.rb')"
</code></pre>
<p>At the very least, you should remove all but the newest
version of each gem plugin, and also remove all gem plugins
that you aren't using (<code>gem uninstall gem_name</code>).</p>
</div>
</div>
<div class='col-12 col-md-3 mt-4' id='sidebar-wrapper'>
<div class='sidebar-nav'>
<h4>Choose version</h4>
<select class='version-selects form-select mb-3'>
<optgroup label='Current release'>
<option value='/v2.3/bundle_exec.html'>
v2.3
</option>
</optgroup>
<optgroup label='Legacy release'>
<option value='/v2.2/bundle_exec.html'>
v2.2
</option>
<option value='/v2.1/bundle_exec.html'>
v2.1
</option>
</optgroup>
<optgroup label='Deprecated release'>
<option value='/v2.0/bundle_exec.html'>
v2.0
</option>
<option value='/v1.17/bundle_exec.html'>
v1.17
</option>
<option value='/v1.16/bundle_exec.html'>
v1.16
</option>
<option value='/v1.15/bundle_exec.html'>
v1.15
</option>
<option value='/v1.14/bundle_exec.html'>
v1.14
</option>
<option selected value='/v1.13/bundle_exec.html'>
v1.13
</option>
<option value='/v1.12/bundle_exec.html'>
v1.12
</option>
</optgroup>
</select>
<h4>Primary Commands</h4>
<ul>
<li class=''>
<a href="/v1.13/man/bundle-install.1.html">bundle install</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-update.1.html">bundle update</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-exec.1.html">bundle exec</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-config.1.html">bundle config</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_help.html">bundle help</a>
</li>
<li class='separator'>
<hr>
</li>
</ul>
<h4>Utilities</h4>
<ul>
<li class=''>
<a href="/v1.13/man/bundle.1.html">bundle</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-binstubs.1.html">bundle binstubs</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_check.html">bundle check</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_clean.html">bundle clean</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_console.html">bundle console</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-gem.1.html">bundle gem</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_init.html">bundle init</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_inject.html">bundle inject</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-lock.1.html">bundle lock</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_open.html">bundle open</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_outdated.html">bundle outdated</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-package.1.html">bundle package</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/bundle-platform.1.html">bundle platform</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_show.html">bundle show</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_version.html">bundle version</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/bundle_viz.html">bundle viz</a>
</li>
<li class='separator'>
<hr>
</li>
<li class=''>
<a href="/v1.13/man/gemfile.5.html">gemfile</a>
</li>
<li class='separator'>
<hr>
</li>
</ul>
</div>
</div>
</div>
</div>
<script src="/commands_layout.min.js"></script>
<div class='bg-light-blue'>
<div class='container'>
<div class='contents'>
<div class='edit-on-github text-center'>
This document is obsolete. <a href="/v2.3/man/bundle-exec.1.html">See the latest version of this document</a> if you caught an error or noticed something was missing, it may be fixed there.
</div>
</div>
</div>
</div>
<div class='footer'>
<nav class='navbar justify-content-center'>
<ul class='navbar-nav'>
<li class='nav-item'><a href="/docs.html" class="nav-link px-3">Docs</a></li>
<li class='nav-item'><a href="/contributors.html" class="nav-link px-3">Team</a></li>
<li class='nav-item'><a href="/blog" class="nav-link px-3">Blog</a></li>
<li class='nav-item'><a href="/about.html" class="nav-link px-3">About</a></li>
<li class='nav-item'><a href="https://github.com/rubygems/rubygems/tree/master/bundler" class="nav-link px-3">Repository</a></li>
</ul>
</nav>
</div>
</body>
</html>