Bundler manages an application's dependencies through its lifecycle for Ruby projects.
Common CLI Commands
bundle install # Install all required gems
bundle install -j4 # Parallel installation using 4 workers
bundle update # Update all gems to newest matching versions
bundle update rails # Update only a specific gem
bundle outdated # Audit outdated gems
bundle exec <command> # Run command in context of the bundle
bundle show <gemname> # Display gem installation directory
bundle info <gemname> # Show gem metadata
bundle gem <my_gem> # Scaffold new gem skeleton
Gemfile Syntax
Basic Declarations
source 'https://rubygems.org'
gem 'rails', '~> 7.1.0'
gem 'pg', '>= 1.5'
gem 'puma'
Git & GitHub References
# Direct GitHub repository
gem 'devise', github: 'heartcombo/devise'
# Specific git branch or tag
gem 'devise', github: 'heartcombo/devise', branch: 'main'
gem 'nokogiri', git: 'https://github.com/sparklemotion/nokogiri.git', tag: 'v1.16.0'
Dependency Groups
group :development, :test do
gem 'rspec-rails'
gem 'factory_bot_rails'
end
group :production do
gem 'aws-sdk-s3'
end
Production Deployment
In CI/CD pipelines and servers, bundle with deployment flags to prevent modifying Gemfile.lock:
# Modern Bundler deployment
bundle config set --local deployment 'true'
bundle config set --local without 'development test'
bundle install
Local Gem Overrides
Point a gem to a local checkout directory for active development:
bundle config local.my_gem ~/Developer/Projects/my_gem