{"record":{"id":"fae1c9bc54befc7b","repo":"ruby/rubygems","slug":"your-ruby-version-is-actual-but-your-gemfile-s","errorCode":null,"errorMessage":"Your Ruby version is #{actual}, but your Gemfile specified #{expected}","messagePattern":"Your Ruby version is #(.+?), but your Gemfile specified #(.+?)","errorType":"exception","errorClass":"RubyVersionMismatch","httpStatus":null,"severity":"error","filePath":"lib/bundler/definition.rb","lineNumber":520,"sourceCode":"      validate_platforms!\n    end\n\n    def validate_ruby!\n      return unless ruby_version\n\n      if diff = ruby_version.diff(Bundler::RubyVersion.system)\n        problem, expected, actual = diff\n\n        msg = case problem\n              when :engine\n                \"Your Ruby engine is #{actual}, but your Gemfile specified #{expected}\"\n              when :version\n                \"Your Ruby version is #{actual}, but your Gemfile specified #{expected}\"\n              when :engine_version\n                \"Your #{Bundler::RubyVersion.system.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}\"\n        end\n\n        raise RubyVersionMismatch, msg\n      end\n    end\n\n    def validate_platforms!\n      return if current_platform_locked? || @platforms.include?(Gem::Platform::RUBY)\n\n      raise ProductionError, \"Your bundle only supports platforms #{@platforms.map(&:to_s)} \" \\\n        \"but your local platform is #{Bundler.local_platform}. \" \\\n        \"Add the current platform to the lockfile with\\n`bundle lock --add-platform #{Bundler.local_platform}` and try again.\"\n    end\n\n    def normalize_platforms\n      resolve.normalize_platforms!(current_dependencies, platforms)\n\n      @resolve = SpecSet.new(resolve.for(current_dependencies, @platforms))\n    end\n\n    def add_platform(platform)","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/ruby/rubygems/blob/86cbb817a38ce8477b181c17467a703ded3f2be8/lib/bundler/definition.rb#L502-L538","documentation":"Definition#validate_ruby! (reached via validate_runtime! when the definition materializes during install, setup or exec) compares the running interpreter against the Gemfile ruby directive; on mismatch it raises Bundler::RubyVersionMismatch showing actual versus expected versions, with engine and engine_version variants (lib/bundler/definition.rb:520). The Gemfile pins the required runtime; the current process violates that pin for the plain version or for the engine constraint.","triggerScenarios":"Gemfile declares `ruby \"3.2.2\"` but the active toolchain is 3.1.4 (rbenv/rvm/asdf local mismatch); CI uses a ruby:3.1 image while the Gemfile pins 3.3; engine directives like `ruby \"...\", engine: \"jruby\"` executed under MRI; cron or Docker entrypoints that bypass version managers and land on system ruby.","commonSituations":"A teammate bumped the pin and the local ruby was never installed; .ruby-version not honored because rbenv or direnv is not initialized in the shell; CI base image drift; running bundle with a different ruby than the app server.","solutions":["Switch to the required ruby: `rbenv install 3.2.2 && rbenv local 3.2.2`, or the rvm or asdf equivalent","Compare `ruby -v` with the RUBY VERSION line in Gemfile.lock to confirm which side is stale","If the pin itself is wrong, update the Gemfile ruby directive and .ruby-version to the intended version, then `bundle install`","Align CI and Docker toolchains with the pin, for example FROM ruby:3.2.2"],"exampleFix":"# before\n# Gemfile: ruby \"3.3.0\"; shell has ruby 3.1.4\n$ bundle install\n# => Your Ruby version is 3.1.4, but your Gemfile specified 3.3.0\n\n# after\n$ rbenv install 3.3.0 && rbenv local 3.3.0\n$ bundle install","handlingStrategy":"validation","validationCode":"required = Bundler.definition.ruby_version\nif required && !required.satisfied_by?(Bundler::RubyVersion.system)\n  abort \"wrong ruby #{RUBY_VERSION}; project requires #{required}\"\nend","typeGuard":null,"tryCatchPattern":"begin\n  Bundler.definition.validate_runtime!\nrescue Bundler::RubyVersionMismatch => e\n  abort \"switch ruby: #{e.message}\"\nend","preventionTips":["Commit .ruby-version alongside the Gemfile ruby directive","Initialize the version manager in cron and Docker shells","Pin CI images and Gemfile ruby to the same version"],"tags":["bundler","ruby-version","runtime-mismatch","rbenv","ci"],"backgroundTag":"runtime-version-mismatch","analyzedSha":"86cbb817a38ce8477b181c17467a703ded3f2be8","analyzedAt":"2026-08-23T06:27:48.159Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}