bundler
Manage Ruby application dependencies
TLDR
View documentation for the original command
SYNOPSIS
bundle subcommand [options] [arguments]
Common Subcommands:
bundle install [options] - Installs gems specified in the Gemfile.
bundle update [gems] [options] - Updates gems to the latest compatible versions.
bundle exec command [arguments] - Executes a command in the context of the bundle.
bundle console [group] - Starts an IRB session in the context of the bundle.
bundle outdated [options] - Lists gems that have newer versions available.
bundle lock [options] - Generates or updates the Gemfile.lock without installing gems.
bundle config [name] [value] - Sets or gets bundler configuration options.
PARAMETERS
Global Options (applicable to many subcommands):
--version
Displays the Bundler version.
--no-color
Disables color output.
--verbose
Prints additional diagnostic information.
For 'bundle install' subcommands:
--path
Installs gems to a specified directory instead of the default RubyGems location. Often used for vendoring dependencies.
--without
Skips installing gems in a specified group (e.g., development, test).
--clean
Removes old installed gems from the bundle.
--jobs
Installs gems in parallel using N jobs.
For 'bundle update' subcommands:
--source
Updates gems from a specific source.
--patch, --minor, --major
Constraints updates to patch, minor, or major versions respectively (used with bundle update --all or bundle update
Note for 'bundle exec':
bundle exec does not have its own specific options; any options following it are passed directly to the executed command. Its purpose is to ensure the command runs within the exact gem environment defined by the Gemfile.lock.
DESCRIPTION
Bundler is the de facto standard dependency management tool for Ruby applications. It provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions needed by a project. This prevents 'dependency hell' where different projects or different developers on the same project might end up with different gem versions, leading to unpredictable behavior or broken builds.
Bundler reads a Gemfile, which specifies a project's dependencies, resolves compatible versions for all gems, and then records these exact versions in a Gemfile.lock file. This Gemfile.lock ensures that anyone else working on the project, or the production deployment, will use the exact same gem versions, guaranteeing reproducibility. It integrates seamlessly with RubyGems and various Ruby frameworks like Rails, making development and deployment predictable and reliable.
CAVEATS
Gemfile.lock Conflicts: Merging Gemfile.lock changes in version control can be challenging, as it's a generated file. It's generally recommended to commit Gemfile.lock to ensure reproducibility.
Performance: Large projects with many dependencies might experience slower bundle install or bundle update times.
Ruby Version Manager Interaction: Bundler works alongside tools like rvm or rbenv. Ensure the correct Ruby version is active before running Bundler commands.
System vs. Binstubs: Using bundle exec is crucial to ensure commands run within the bundle's environment. Without it, you might be running system-wide gem versions, leading to unexpected behavior.
GEMFILE
A file named Gemfile (without an extension) located in the root of a Ruby project. It specifies all the gems and their versions (or version constraints) that the project depends on. It uses a Ruby DSL (Domain Specific Language) to define these dependencies, often grouped by environment (e.g., development, test, production).
GEMFILE.LOCK
A file automatically generated and updated by Bundler (via bundle install, bundle update). It precisely records the exact versions of all gems (including transitive dependencies) that were installed for the project. This file is critical for ensuring consistent and reproducible environments across different machines and deployments. It should always be committed to version control.
BINSTUBS
Executable scripts generated by Bundler (via bundle install --binstubs or bundle binstubs). These scripts are proxies that ensure a command (like rails or rake) is executed using the gems from the project's bundle, rather than potentially conflicting system-wide gems.
HISTORY
Bundler emerged around 2009-2010 to address the pervasive "dependency hell" problem in the Ruby ecosystem, especially with the growth of Ruby on Rails applications. Before Bundler, managing gem versions across different projects and development environments was a significant pain point, often leading to unpredictable behavior. It quickly became the de facto standard tool for Ruby dependency management, making reproducible builds and deployments much more reliable and straightforward. Its core concepts, like the Gemfile and Gemfile.lock, have influenced dependency management tools in other languages.