| name | bundler |
| description | This skill should be used when the user asks about "Bundler", "Gemfile", "Gemfile.lock", "bundle install", "bundle update", "bundle exec", "dependency management", "gem versions", "gem groups", "bundle add", "gem sources", or needs guidance on managing Ruby dependencies. |
| version | 1.0.0 |
Bundler Dependency Management
Guide to managing Ruby gem dependencies with Bundler.
Gemfile Basics
Structure
source "https://rubygems.org"
ruby "3.2.0"
gem "rails", "~> 7.1"
gem "pg", ">= 1.0"
gem "puma"
Version Constraints
gem "rails", "7.1.0"
gem "pg", ">= 1.0"
gem "rails", "~> 7.1"
gem "rails", "~> 7.1.0"
gem "rails", "~> 7.1.2.3"
gem "nokogiri", ">= 1.12", "< 2.0"
gem "puma"
Gem Groups
gem "rails"
group :development do
gem "better_errors"
gem "binding_of_caller"
end
group :test do
gem "rspec-rails"
gem "capybara"
end
group :development, :test do
gem "factory_bot_rails"
gem "faker"
end
group :production do
gem "redis"
end
Install Without Groups
bundle config set --local without development test
bundle install
Gem Sources
Alternative Sources
source "https://rubygems.org"
source "https://gems.example.com" do
gem "private_gem"
end
Git Repositories
gem "rails", github: "rails/rails"
gem "rails", github: "rails/rails", branch: "main"
gem "rails", github: "rails/rails", tag: "v7.1.0"
gem "rails", github: "rails/rails", ref: "abc123"
gem "my_gem", git: "https://github.com/user/my_gem.git"
gem "my_gem", git: "git@github.com:user/my_gem.git"
gem "my_gem", github: "user/monorepo", glob: "gems/my_gem/*.gemspec"
Local Path
gem "my_gem", path: "../my_gem"
gem "my_gem", path: "~/projects/my_gem"
Platforms and Requirements
Platform-Specific Gems
gem "bcrypt", platforms: :ruby
gem "wdm", platforms: :mswin
gem "sqlite3", platforms: [:ruby, :mswin]
Ruby Version Requirements
ruby "3.2.0"
ruby "3.2.0", engine: "jruby", engine_version: "9.4.0"
ruby "~> 3.2.0"
Lock File
Understanding Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
actionpack (7.1.0)
actionview (= 7.1.0)
activesupport (= 7.1.0)
rack (~> 2.2)
PLATFORMS
arm64-darwin-22
aarch64-linux
x86_64-linux
DEPENDENCIES
rails (~> 7.1)
RUBY VERSION
ruby 3.2.0p0
BUNDLED WITH
2.4.0
Managing Platforms
bundle lock --add-platform x86_64-linux aarch64-linux arm64-darwin
bundle lock --remove-platform x86_64-linux
bundle lock --update
Common Commands
Install and Update
bundle install
bundle update
bundle update rails pg
bundle update --conservative rails
bundle update --patch
bundle update --minor
Dependency Information
bundle info rails
bundle show
bundle list
bundle outdated
bundle audit
Execution
bundle exec rails server
bundle exec rspec
bundle binstubs rspec-core
bin/rspec
EDITOR=code bundle open rails
Configuration
Bundle Config
bundle config set --local path vendor/bundle
bundle config set --local without development test
bundle config list
bundle config unset path
Common Settings
bundle config set --local path vendor/bundle
bundle config set --local jobs 4
bundle config set --local disable_shared_gems true
bundle config set --local system true
Configuration File
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "development:test"
BUNDLE_JOBS: "4"
Troubleshooting
Common Issues
rm -rf vendor/bundle .bundle Gemfile.lock
bundle install
bundle install --redownload
bundle install --verbose
bundle check
Version Conflicts
bundle update conflicting_gem
bundle viz
Native Extensions
bundle config build.nokogiri --use-system-libraries
bundle install
bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
Best Practices
Version Constraints
gem "rails", "~> 7.1"
gem "rails", "7.1.0"
gem "rails"
Group Organization
group :development do
end
group :test do
end
group :development, :test do
end
Lock File Management
- Always commit
Gemfile.lock
- Update lock file deliberately, not accidentally
- Review changes to lock file in PRs
- Periodically run
bundle update to get security patches
CI/CD
bundle config set --local frozen true
bundle config set --local deployment true
bundle install --jobs 4 --retry 3
Gemfile.lock vs Gemfile
| Gemfile | Gemfile.lock |
|---|
| Dependencies you want | Exact versions resolved |
| Version constraints | Specific versions |
| Human-edited | Machine-generated |
| Flexible | Deterministic |
| What you need | What you have |
Always commit both files. The lock file ensures everyone uses identical gem versions.