Skip to content
Latchkey

Bundler "Could not find X in any of the sources" in CI

Bundler resolved the lockfile but could not download one gem: no configured source (RubyGems, a mirror, or a git/path source) publishes the exact name and version the lock pins. On CI it is usually a missing source or a cache that did not restore.

What this error means

bundle install stops with "Could not find gem-name (x.y.z) in any of the sources" and lists the sources it searched. The build fails before any test runs.

Bundler
Fetching gem metadata from https://rubygems.org/.........
Could not find rails-html-sanitizer-1.6.0 in any of the sources
Run `bundle install` to install missing gems.

Common causes

The gem version is not on the configured source

The lockfile pins a version that a private mirror or vendored cache does not carry, so no source can supply it.

A vendored bundle cache was not restored

CI expected vendor/bundle or vendor/cache from a cache action, but the cache key missed, so the gem is absent locally.

How to fix it

Confirm the source and reinstall

  1. Check that the source line in the Gemfile points at a registry carrying the version.
  2. If you use a mirror, verify the mirror mirrors the pinned version.
  3. Re-run bundle install so the gem is fetched fresh.
Terminal
bundle config set --local mirror.https://rubygems.org https://your-mirror.example.com
bundle install

Restore the gem cache correctly

Cache the bundle path and key it on the lockfile so the exact gems are available on every run.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: vendor/bundle
    key: gems-${{ hashFiles('Gemfile.lock') }}

How to prevent it

  • Commit Gemfile.lock so CI installs the same versions every run.
  • Key the bundle cache on Gemfile.lock so a lock change busts it.
  • Mirror all pinned versions if you install from a private source.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →