Skip to content
Latchkey

Bundler "Your Ruby version is X, but your Gemfile specified Y" in CI

The Gemfile declares a required Ruby with a ruby directive, and Bundler compared it against the interpreter running on the runner. They differ, so Bundler refuses to install against the wrong Ruby.

What this error means

bundle install or bundle exec fails with "Your Ruby version is 3.2.2, but your Gemfile specified 3.3.0", because setup-ruby installed a version that does not match the Gemfile.

bundler
Your Ruby version is 3.2.2, but your Gemfile specified 3.3.0

Common causes

The CI Ruby differs from the Gemfile directive

setup-ruby (or the image default) provisioned a Ruby that does not satisfy the ruby version pinned in the Gemfile.

The .ruby-version and Gemfile disagree

A version file and the Gemfile directive specify different versions, so whichever the runner uses conflicts with the other.

How to fix it

Provision the Ruby the Gemfile requires

  1. Read the ruby directive in the Gemfile.
  2. Set the same version in setup-ruby (or .ruby-version).
  3. Re-run so the active Ruby matches the Gemfile.
.github/workflows/ci.yml
- uses: ruby/setup-ruby@v1
  with:
    ruby-version: '3.3.0'

Read the version from .ruby-version

Let setup-ruby pick up the project version file so CI and the Gemfile stay aligned.

.github/workflows/ci.yml
- uses: ruby/setup-ruby@v1
  with:
    ruby-version: .ruby-version

How to prevent it

  • Keep .ruby-version, the Gemfile ruby directive, and CI in sync.
  • Drive the CI Ruby from .ruby-version to avoid drift.
  • Bump all three together when upgrading Ruby.

Related guides

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