Skip to content
Latchkey

LoadError: cannot load such file in CI

A require could not find the named file on the Ruby load path. Either the file does not exist where Ruby looked, or it is a gem that was never installed into the bundle.

What this error means

Boot or a test fails immediately at a require line. The message names the path or library that could not be loaded. It often passes locally where the file path or a globally installed gem happened to resolve.

ruby
LoadError: cannot load such file -- redis
        from config/initializers/cache.rb:1:in `require'

Common causes

Gem not in the bundle

You required a library that is not listed in the Gemfile, so it was never installed on the runner even though it may be present globally on your machine.

Wrong relative path

A plain require expects a load-path entry, not a relative path. A local file needs require_relative or the directory added to $LOAD_PATH.

File renamed or not checked in

The required file was renamed, moved, or never committed, so it is missing on the fresh checkout.

How to fix it

Add the gem and bundle it

If the require targets a gem, declare it so CI installs it.

Gemfile
# Gemfile
gem 'redis'

bundle install

Use require_relative for project files

  1. For a file in your own tree, switch require to require_relative with the correct relative path.
  2. Confirm the file is committed and present on a clean checkout.
  3. Avoid depending on globally installed gems; everything runtime needs must be in the Gemfile.

How to prevent it

  • Run code through bundle exec so only bundled gems are on the path.
  • Prefer require_relative for in-project files.
  • Verify a clean checkout boots before relying on local state.

Related guides

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