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.
<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.
gem install bundler
# or the version the lockfile pins
gem install bundler -v "$(tail -1 Gemfile.lock | tr -d ' ')"
bundle --versionConfirm the interpreter and gem env
- Run ruby -v and which ruby to confirm the expected interpreter is active.
- Run gem env to check GEM_HOME and that Bundler is in the gem path.
- 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.