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::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 checkCommon 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.
bundle install --redownload
# or refresh a single installed gem from its source
gem pristine nokogiriClear the gem cache and reinstall
- Delete the cached gems (rm -rf vendor/cache and the gem cache dir).
- Re-run bundle install to fetch clean copies.
- 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.