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.
/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
- Add the missing library to the correct group in the Gemfile.
- Run bundle install and commit the updated lock.
- Re-run so bundle exec can load it.
# Gemfile
group :test do
gem 'rspec'
endInstall the group CI needs
If a needed gem is in a skipped group, stop excluding that group in CI so its gems install.
bundle config set --local without production
bundle installHow 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.