Skip to content
Latchkey

Bundler Corrupt / Incomplete Gem in Cache - Redownload in CI

A cached .gem file is corrupt or was truncated mid-download, so unpacking it fails. Re-downloading the gem replaces the bad copy and clears the error - a mechanical, transient fault.

What this error means

bundle install fails unpacking a specific gem with "package is corrupt", a Zlib inflate error, or a checksum mismatch. It points at one cached .gem; other gems are fine.

bundler output
Bundler::GenericSystemCallError: Unknown error while installing nokogiri.
There was an error while trying to install nokogiri (1.16.0):
package is corrupt, exception while verifying: ...
Zlib::DataError: incorrect header check

Common causes

Truncated download into the gem cache

A connection dropped mid-download and left a partial .gem in the cache. The next install tries to unpack the truncated file and fails.

A corrupted cached gem restored in CI

A bundle cache that captured a bad .gem (or one corrupted in transit) gets restored, so the corruption persists across runs until the file is replaced.

How to fix it

Redownload the gems

Force Bundler to fetch fresh copies, replacing the corrupt cached file.

Terminal
bundle install --redownload
# or refresh a single installed gem from its source
gem pristine nokogiri

Clear the gem cache and reinstall

  1. Delete the cached gems (rm -rf vendor/cache and the gem cache dir).
  2. Re-run bundle install to fetch clean copies.
  3. Invalidate the CI cache key so the corrupt artifact is not restored again.

How to prevent it

  • Bust the bundle cache key when corruption recurs so a bad artifact is not reused.
  • Set a Bundler retry count so truncated downloads are re-attempted.
  • Verify cache integrity, or cache the installed bundle rather than raw .gem files.

Frequently asked questions

What causes "corrupt cached gem"?
A connection dropped mid-download and left a partial .gem in the cache. The next install tries to unpack the truncated file and fails.
How do I fix corrupt cached gem?
Force Bundler to fetch fresh copies, replacing the corrupt cached file.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card