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.
Your Ruby version is 3.2.2, but your Gemfile specified 3.3.0Common 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
- Read the ruby directive in the Gemfile.
- Set the same version in setup-ruby (or .ruby-version).
- Re-run so the active Ruby matches the Gemfile.
- 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.
- uses: ruby/setup-ruby@v1
with:
ruby-version: .ruby-versionHow 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.