Skip to content

/commands/bundler/bundle-update-single-gem

bundle update gemname --conservative: update one gem without the others

The commands on this page have not been executed by our verification runner yet.updated
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

bash
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 file

After the update, run your tests with bundle exec, then commit Gemfile.lock.

Options

OptionWhat it does
bundle update GEMUpdate GEM and the gems it depends on
--conservativeDo not update dependencies shared with other gems unless required
--patch / --minor / --majorPrefer the newest patch, minor or major version (major is the default)
--strictNever go past the chosen level, even if that leaves a gem older
--group NAMEUpdate every gem in that Gemfile group
--source GEMUpdate a gem that comes from a git or path source
--localUse only gems already installed or cached, no network
--allUpdate every gem (same as no gem name)

Pitfalls

  • Gemfile constraints win. With gem "rails", "~> 7.1.0" in the Gemfile, bundle update rails stays on 7.1.x. To move to a newer series, change the constraint first, then run bundle update rails.
  • Activation conflicts. Running a command without bundle exec after 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-linux so the lock file works there.
  • Update vs install. bundle install installs 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.

Sources