Skip to content
Latchkey

Ruby "cannot load such file -- bundler/setup" in CI

Ruby tried to require bundler/setup and could not find Bundler at all. Bundler is not installed for the interpreter running the code, or PATH/GEM_HOME points at a different Ruby than the one with Bundler.

What this error means

A program or rake task that begins with require "bundler/setup" fails immediately with LoadError "cannot load such file -- bundler/setup". The bundle never loads because Bundler itself is missing for this Ruby.

Ruby traceback
<internal:/usr/lib/ruby/.../rubygems/core_ext/kernel_require.rb>:in
`require': cannot load such file -- bundler/setup (LoadError)

Common causes

Bundler not installed for this Ruby

A minimal image or a freshly built rbenv Ruby may have no Bundler gem installed, so bundler/setup cannot be required.

Wrong interpreter active

PATH resolves a Ruby that lacks Bundler (a system Ruby ahead of the rbenv shim), or GEM_HOME points at a gem dir without Bundler.

How to fix it

Install Bundler for the active Ruby

Install the Bundler version the lockfile expects, then verify it is reachable.

Terminal
gem install bundler
# or the version the lockfile pins
gem install bundler -v "$(tail -1 Gemfile.lock | tr -d ' ')"
bundle --version

Confirm the interpreter and gem env

  1. Run ruby -v and which ruby to confirm the expected interpreter is active.
  2. Run gem env to check GEM_HOME and that Bundler is in the gem path.
  3. For rbenv, run rbenv rehash after installing Bundler so the shim appears.

How to prevent it

  • Let setup-ruby install the lockfile Bundler (bundler: Gemfile.lock).
  • Bake Bundler into images that run Ruby code.
  • Run gem env early in CI to confirm the interpreter and gem paths.

Related guides

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