LinuxCommandLibrary

bundle

Manage Ruby gem dependencies for a project

TLDR

Install all gems defined in the Gemfile expected in the working directory

$ bundle install
copy

Execute a command in the context of the current bundle
$ bundle exec [command] [arguments]
copy

Update all gems by the rules defined in the Gemfile and regenerate Gemfile.lock
$ bundle update
copy

Update one or more specific gem(s) defined in the Gemfile
$ bundle update [gem_name1] [gem_name2]
copy

Update one or more specific gems(s) defined in the Gemfile but only to the next patch version
$ bundle update --patch [gem_name1] [gem_name2]
copy

Update all gems within the given group in the Gemfile
$ bundle update --group [development]
copy

List installed gems in the Gemfile with newer versions available
$ bundle outdated
copy

Create a new gem skeleton
$ bundle gem [gem_name]
copy

SYNOPSIS

bundle <command> [arguments] [options]

Examples:
bundle install [options]
bundle update [gems] [options]
bundle exec command [arguments]
bundle add gem_name [options]

PARAMETERS

--local
    Do not fetch remote gems; use only cached gems.

--path <directory>
    Install gems to a specified directory rather than the system-wide Gem Path. Often used for vendoring dependencies.

--without <groups>
    Do not install gems belonging to the specified groups (e.g., 'development test').

--clean
    Removes old gems from the bundle directory after installation (only applicable when using --path).

--force
    Reinstall all gems, even if they appear to be installed.

--no-install
    Resolves dependencies and updates Gemfile.lock without actually installing gems.

--gemfile <file>
    Use a specific Gemfile instead of the default.

--verbose
    Print extra information for debugging purposes.

DESCRIPTION

bundle is the primary command-line interface for Bundler, a dependency manager for Ruby applications. It ensures that a Ruby application runs with the specific versions of gems (libraries) it needs. Bundler achieves this by reading a Gemfile, which specifies an application's dependencies, and then resolving and installing those gems. It creates a Gemfile.lock file, which precisely records the versions of all installed gems, ensuring consistent environments across development, testing, and production. bundle provides various subcommands to manage the entire dependency lifecycle, including installing, updating, and executing commands within the bundled environment. It is crucial for maintaining project stability and portability in the Ruby ecosystem.

CAVEATS

bundle is not a standard utility shipped with most Linux distributions. It must be installed separately, typically via gem install bundler, after Ruby is set up. It is specifically designed for Ruby projects and is not applicable to other programming languages or general system dependency management. Its functionality relies heavily on the presence of a Gemfile in the project directory.

SUBCOMMANDS

bundle acts as a front-end for a rich set of subcommands, each designed for a specific dependency management task. Examples include install (to resolve and install gems), update (to update gems to newer versions), exec (to run a command within the bundled environment), add (to add new gem dependencies), show (to display installed gems), and config (to manage Bundler settings).

GEMFILE AND GEMFILE.LOCK

These two files are central to Bundler's operation. The Gemfile declares the project's direct gem dependencies, while the Gemfile.lock is a generated file that precisely records the exact versions of all gems (including transitive dependencies) that were resolved and installed. This ensures that anyone running bundle install on the same project gets the exact same gem setup, promoting consistency across environments.

HISTORY

Bundler was first released in 2010 to address the growing need for consistent and reproducible dependency management within Ruby projects. Before Bundler, managing gem dependencies was often manual and prone to 'works on my machine' issues due to differing gem versions across development environments. It quickly became the de-facto standard for Ruby dependency resolution, integrating seamlessly with RubyGems. Its adoption by the Ruby on Rails framework further solidified its position as an essential tool in the Ruby ecosystem, ensuring project stability and easing collaboration among developers.

SEE ALSO

gem(1), ruby(1), rake(1), rails(1), rbenv(1), rvm(1)

Copied to clipboard