/commands/bundler/bundle-update-single-gem
bundle update gemname --conservative: update one gem without the others
- tool
- Bundler
- versions
- Bundler 2.x
- os
- any
bundle update nokogiri updates only the nokogiri gem (and the gems it depends on) to the newest versions the Gemfile allows, and rewrites Gemfile.lock; every other gem keeps its locked version. Add --conservative to keep even shared dependencies where they are unless the update really needs them. bundle update without a gem name updates everything, which is rarely what you want in an existing application.
Usage
bundle outdated # what is behind
bundle update nokogiri # one gem and its dependencies
bundle update nokogiri --conservative # one gem, shared dependencies stay put
bundle update rails --patch # only patch versions (x.y.Z)
bundle update rails --minor --strict # minor at most, for every gem touched
bundle update --group test # every gem of one Gemfile group
bundle update --ruby # only refresh the Ruby version in the lock file
bundle update --bundler # update the BUNDLED WITH version in the lock fileAfter the update, run your tests with bundle exec, then commit Gemfile.lock.
Options
| Option | What it does |
|---|---|
| bundle update GEM | Update GEM and the gems it depends on |
| --conservative | Do not update dependencies shared with other gems unless required |
| --patch / --minor / --major | Prefer the newest patch, minor or major version (major is the default) |
| --strict | Never go past the chosen level, even if that leaves a gem older |
| --group NAME | Update every gem in that Gemfile group |
| --source GEM | Update a gem that comes from a git or path source |
| --local | Use only gems already installed or cached, no network |
| --all | Update every gem (same as no gem name) |
Pitfalls
- Gemfile constraints win. With
gem "rails", "~> 7.1.0"in the Gemfile,bundle update railsstays on 7.1.x. To move to a newer series, change the constraint first, then runbundle update rails. - Activation conflicts. Running a command without
bundle execafter an update can load a different version than the lock file and fail with You have already activated. Use bundle exec or binstubs. - Native gems. Gems such as nokogiri or pg compile extensions or ship platform builds. Add the platforms you deploy to with
bundle lock --add-platform x86_64-linuxso the lock file works there. - Update vs install.
bundle installinstalls what the lock file lists and never upgrades locked gems; see bundle install vs bundle update.
How to confirm it worked
Bundler prints the gems it installed, marking upgrades with the old version in parentheses. git diff Gemfile.lock shows exactly which versions changed, and bundle info nokogiri (or bundle exec gem list nokogiri) prints the version now in use.
FAQ
Does bundle update rails update every gem?
It updates rails and, by default, the gems rails depends on, as far as other gems allow. Add --conservative to keep shared dependencies at their locked versions unless the new rails version requires something newer.
How do I update only to patch versions?
Run bundle update gemname --patch. --minor allows minor updates, --major is the default, and --strict makes Bundler refuse to go beyond the chosen level for any gem in the update.
Why did bundle update not change the gem version?
The Gemfile constraint, another gem's dependency or your Ruby version keeps it where it is. Check the constraint in the Gemfile, then run bundle outdated gemname to see the newest version and what it requires.