Bundler "Your Gemfile.lock is corrupt" in CI
Bundler validates the structure of Gemfile.lock before installing. When a gem appears in one section but not the matching one - usually after a bad merge or a hand-edit - Bundler calls the lockfile corrupt and refuses to install from it.
What this error means
bundle install fails with "Your Gemfile.lock is corrupt. The following gem is missing from the DEPENDENCIES section: '<gem>'." Often the lockfile contains leftover merge-conflict markers.
Your Gemfile.lock is corrupt. The following gem is missing from the
DEPENDENCIES section: 'nokogiri'Common causes
A merge conflict was resolved incorrectly
Two branches changed Gemfile.lock and the resolution left the GEM, DEPENDENCIES, and BUNDLED WITH sections out of sync.
The lockfile was hand-edited
A manual edit removed or duplicated a gem entry, breaking the invariant Bundler expects between sections.
How to fix it
Regenerate the lockfile cleanly
Let Bundler rewrite a consistent lockfile from the Gemfile rather than patching it by hand.
# discard the broken lock and re-resolve
rm Gemfile.lock
bundle install
git add Gemfile.lockCheck for leftover conflict markers
- Open Gemfile.lock and search for <<<<<<<, =======, >>>>>>>.
- Resolve the conflict in the Gemfile, then regenerate the lock with bundle install.
- Commit the regenerated lockfile, not a hand-merged one.
How to prevent it
- Resolve Gemfile.lock conflicts by re-running bundle install, never by hand-merging sections.
- Avoid editing Gemfile.lock manually; change the Gemfile and let Bundler regenerate.
- Add a CI check that bundle install --frozen produces no diff.