{
    "mode": "man",
    "parameter": "BUNDLE-EXEC",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/BUNDLE-EXEC/json",
    "generated": "2026-10-22T12:35:08Z",
    "synopsis": "bundle exec [--keep-file-descriptors] command",
    "sections": {
        "NAME": {
            "content": "bundle-exec - Execute a command in the context of the bundle\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "bundle exec [--keep-file-descriptors] command\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This  command executes the command, making all gems specified in the [Gemfile(5)][Gemfile(5)]\navailable to require in Ruby programs.\n\nEssentially, if you would normally have run something like  rspec  spec/myspec.rb,  and  you\nwant  to  use the gems specified in the [Gemfile(5)][Gemfile(5)] and installed via bundle in‐\nstall(1) bundle-install.1.html, you should run bundle exec rspec spec/myspec.rb.\n\nNote that bundle exec does not require that an executable is available on your shell´s $PATH.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "--keep-file-descriptors",
                    "content": "Exec in Ruby 2.0 began discarding non-standard file descriptors.  When  this  flag  is\npassed,  exec  will revert to the 1.9 behaviour of passing all file descriptors to the\nnew process.\n",
                    "long": "--keep-file-descriptors"
                }
            ]
        },
        "BUNDLE INSTALL --BINSTUBS": {
            "content": "If you use the --binstubs flag in bundle install(1) bundle-install.1.html, Bundler will auto‐\nmatically create a directory (which defaults to approot/bin) containing all of the  executa‐\nbles available from gems in the bundle.\n\nAfter  using  --binstubs,  bin/rspec  spec/myspec.rb  is  identical  to  bundle  exec  rspec\nspec/myspec.rb.\n",
            "subsections": []
        },
        "ENVIRONMENT MODIFICATIONS": {
            "content": "bundle exec makes a number of changes to the shell environment, then executes the command you\nspecify in full.\n\n•   make sure that it´s still possible to shell out to bundle from inside a  command  invoked\nby bundle exec (using $BUNDLEBINPATH)\n\n•   put  the  directory containing executables (like rails, rspec, rackup) for your bundle on\n$PATH\n\n•   make sure that if bundler is invoked in the subshell, it uses the same Gemfile  (by  set‐\nting BUNDLEGEMFILE)\n\n•   add  -rbundler/setup to $RUBYOPT, which makes sure that Ruby programs invoked in the sub‐\nshell can see the gems in the bundle\n\n\n\nIt also modifies Rubygems:\n\n•   disallow loading additional gems not in the bundle\n\n•   modify the gem method to be a no-op if a gem matching the requirements is in the  bundle,\nand to raise a Gem::LoadError if it´s not\n\n•   Define  Gem.refresh  to  be  a  no-op, since the source index is always frozen when using\nbundler, and to prevent gems from the system leaking into the environment\n\n•   Override Gem.binpath to use the gems in the bundle, making system executables work\n\n•   Add all gems in the bundle into Gem.loadedspecs\n\n\n\nFinally, bundle exec also implicitly modifies Gemfile.lock if the lockfile and the Gemfile do\nnot match. Bundler needs the Gemfile to determine things such as a gem´s groups, autorequire,\nand platforms, etc., and that information isn´t stored in the lockfile. The Gemfile and lock‐\nfile must be synced in order to bundle exec successfully, so bundle exec updates the lockfile\nbeforehand.\n",
            "subsections": [
                {
                    "name": "Loading",
                    "content": "By default, when attempting to bundle exec to a file with a ruby shebang, Bundler  will  Ker‐\nnel.load  that  file  instead of using Kernel.exec. For the vast majority of cases, this is a\nperformance improvement. In a rare few cases, this could cause some subtle side-effects (such\nas dependence on the exact contents of $0 or FILE) and the optimization can  be  disabled\nby enabling the disableexecload setting.\n"
                },
                {
                    "name": "Shelling out",
                    "content": "Any  Ruby code that opens a subshell (like system, backticks, or %x{}) will automatically use\nthe current Bundler environment. If you need to shell out to a Ruby command that is not  part\nof your current bundle, use the withunbundledenv method with a block. Any subshells created\ninside  the block will be given the environment present before Bundler was activated. For ex‐\nample, Homebrew commands run Ruby, but don´t work inside a bundle:\n\n\n\nBundler.withunbundledenv do\n`brew install wget`\nend\n\n\n\nUsing withunbundledenv is also necessary if you are shelling out to a different bundle. Any\nBundler commands run in a subshell will inherit the current Gemfile, so commands that need to\nrun in the context of a different bundle also need to use withunbundledenv.\n\n\n\nBundler.withunbundledenv do\nDir.chdir \"/other/bundler/project\" do\n`bundle exec ./script`\nend\nend\n\n\n\nBundler provides convenience helpers that wrap system and exec, and they  can  be  used  like\nthis:\n\n\n\nBundler.cleansystem(´brew install wget´)\nBundler.cleanexec(´brew install wget´)\n\n\n"
                }
            ]
        },
        "RUBYGEMS PLUGINS": {
            "content": "At  present,  the  Rubygems  plugin system requires all files named rubygemsplugin.rb on the\nload path of any installed gem when any Ruby code requires rubygems.rb.  This  includes  exe‐\ncutables installed into the system, like rails, rackup, and rspec.\n\nSince Rubygems plugins can contain arbitrary Ruby code, they commonly end up activating them‐\nselves or their dependencies.\n\nFor instance, the gemcutter 0.5 gem depended on jsonpure. If you had that version of gemcut‐\nter installed (even if you also had a newer version without this problem), Rubygems would ac‐\ntivate gemcutter 0.5 and jsonpure <latest>.\n\nIf  your  Gemfile(5)  also contained jsonpure (or a gem with a dependency on jsonpure), the\nlatest version on your system might conflict with the version  in  your  Gemfile(5),  or  the\nsnapshot version in your Gemfile.lock.\n\nIf this happens, bundler will say:\n\n\n\nYou have already activated jsonpure 1.4.6 but your Gemfile\nrequires jsonpure 1.4.3. Consider using bundle exec.\n\n\n\nIn  this  situation, you almost certainly want to remove the underlying gem with the problem‐\natic gem plugin. In general, the authors of these plugins (in this case, the  gemcutter  gem)\nhave released newer versions that are more careful in their plugins.\n\nYou can find a list of all the gems containing gem plugins by running\n\n\n\nruby -e \"puts Gem.findfiles(´rubygemsplugin.rb´)\"\n\n\n\nAt  the very least, you should remove all but the newest version of each gem plugin, and also\nremove all gem plugins that you aren´t using (gem uninstall gemname).\n\nAugust 2023                              BUNDLE-EXEC(1)",
            "subsections": []
        }
    },
    "summary": "bundle-exec - Execute a command in the context of the bundle",
    "flags": [
        {
            "flag": "",
            "long": "--keep-file-descriptors",
            "arg": null,
            "description": "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."
        }
    ],
    "examples": [],
    "see_also": []
}