Bundler "Your Ruby version is X" - Fix with rbenv local in CI
Bundler reports a Ruby mismatch because rbenv is resolving a different version than the Gemfile requires. The project has no .ruby-version (or it disagrees), so rbenv falls back to the global Ruby. Setting the project version with rbenv local fixes it.
What this error means
Under rbenv, bundle commands fail with "Your Ruby version is X, but your Gemfile specified Y". rbenv version shows the global Ruby is active in the project directory rather than the one the Gemfile pins.
$ rbenv version
3.2.2 (set by /home/runner/.rbenv/version)
$ bundle install
Your Ruby version is 3.2.2, but your Gemfile specified 3.3.0Common causes
No project .ruby-version, so global wins
Without a .ruby-version in the project, rbenv uses the global version. If that differs from the Gemfile’s ruby requirement, Bundler rejects it.
The required Ruby is not installed under rbenv
Even with rbenv local set, if the named version is not installed, rbenv cannot select it and the wrong version stays active.
How to fix it
Set the project Ruby with rbenv local
Install the required version and pin it for the project so rbenv selects it.
rbenv install -s 3.3.0
rbenv local 3.3.0
rbenv rehash
ruby --version # confirm it matches the GemfileAlign the Gemfile and .ruby-version
- Make the Gemfile ruby requirement and .ruby-version name the same version.
- Commit .ruby-version so every runner resolves the same Ruby.
- Confirm rbenv version reports the project version, not the global one.
How to prevent it
- Commit .ruby-version (via rbenv local) aligned with the Gemfile.
- Install the pinned Ruby under rbenv before bundling.
- Prefer setup-ruby, which reads .ruby-version and avoids global fallback.