Skip to content
Latchkey

Bundler "bundle exec" "cannot load such file" in CI

Under bundle exec, Ruby loads only what the bundle provides. "cannot load such file" means the required library is not a gem in the Gemfile, or the load path does not include your own project code.

What this error means

A bundle exec command fails with "cannot load such file -- name (LoadError)". It works locally where the file or gem happens to be on the load path.

Ruby
/usr/local/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb:136:in `require':
cannot load such file -- rspec/core/rake_task (LoadError)

Common causes

The gem is missing from the Gemfile

The library is installed globally on a developer machine but is not in the Gemfile, so under bundle exec it is not on the load path.

A gem is in a group not installed in CI

The dependency lives in the development or test group that CI excluded via --without, so it is not loaded.

How to fix it

Add the gem to the Gemfile

  1. Add the missing library to the correct group in the Gemfile.
  2. Run bundle install and commit the updated lock.
  3. Re-run so bundle exec can load it.
Gemfile
# Gemfile
group :test do
  gem 'rspec'
end

Install the group CI needs

If a needed gem is in a skipped group, stop excluding that group in CI so its gems install.

Terminal
bundle config set --local without production
bundle install

How to prevent it

  • Declare every runtime and tooling dependency in the Gemfile.
  • Match the installed bundle groups to what CI actually runs.
  • Run tools via bundle exec locally so missing gems surface early.

Related guides

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