rbenv ".ruby-version" Mismatch in CI - Wrong Ruby Selected
rbenv picks the Ruby named in .ruby-version (or RBENV_VERSION), but the runner is running a different one - usually because the requested version is not installed, or PATH resolves a system Ruby ahead of the rbenv shim.
What this error means
ruby --version in CI prints a different version than .ruby-version requests, or a later Bundler step complains about a Ruby mismatch. The shim is being bypassed or the requested version is absent.
$ cat .ruby-version
3.3.0
$ ruby --version
ruby 3.2.2p53 # system Ruby, not the rbenv-managed 3.3.0Common causes
rbenv shims not on PATH first
If ~/.rbenv/shims is not ahead of /usr/bin on PATH, a system Ruby answers first and .ruby-version is effectively ignored.
rbenv not initialized in the shell
Without rbenv init (or eval "$(rbenv init -)"), the shims are not active, so rbenv never intercepts the ruby call.
How to fix it
Initialize rbenv and put shims first
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - bash)"
rbenv local 3.3.0
ruby --version # confirm it matches .ruby-versionConfirm which Ruby rbenv resolves
Check that rbenv reports the expected version and points at the shim.
rbenv version
rbenv which rubyHow to prevent it
- Initialize rbenv early so its shims lead PATH in every step.
- Commit .ruby-version and keep it aligned with the Gemfile.
- Prefer setup-ruby in CI, which reads .ruby-version and avoids shim ordering issues.