published fresh until

Ruby: upgrade runtime and repair native gem installs

Summary Keep compatible locked dependencies, add deployment platforms before freezing, and rebuild native gems under the target Ruby with matching headers and compiler tools. Deployment must reject lockfile changes; set BUNDLE_FROZEN

Not for Ruby regexp security patch selection; see ruby-regexp-compiler-gitlab-cves-upgrade-rbenv-asdf-docker.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run ruby -v and bundle config list, then compare the active interpreter and Bundler selection with the Gemfile and BUNDLED WITH before changing the lockfile.

Short answer

As of November 2026, the release reference is Ruby 4.0.9, October 23; the command reference targets Bundler 4.1.0, November 16. Use these as references; choose the application's target Ruby branch deliberately. Prepare a compatible lockfile on the target Ruby with all deployment platforms, rebuild native gems there, then require an unchanged lockfile in deployment. An install alone does not establish that an extension can load.

Choose / don't choose

  • Keep the locked versions: choose when gem requirements and artifacts support the new interpreter; don't discard the lockfile to repair compiled files. bundle install preserves unchanged dependencies (install reference).
  • Source compilation: choose when no compatible binary exists; don't enable it merely because Ruby changed. Nokogiri recommends compatible precompiled gems (maintainer guide).
  • Selective dependency update: choose when a locked gem cannot support the target Ruby; don't expect recompilation to fix incompatible Ruby APIs. Use bundle update nokogiri --conservative for that gem rather than updating the entire bundle (update reference).

Not for: Ruby regexp security patch selection; see ruby-regexp-compiler-gitlab-cves-upgrade-rbenv-asdf-docker.

Settings that matter

Rows apply to Bundler 4.1.0 docs as of November 2026 (package requirements).

Setting or flagValue / defaultApplies toSource
frozen / BUNDLE_FROZENDisallow automatic changes to Gemfile.lock; commands are blocked unless it can be installed exactly as writtenCurrent Bundler docsconfig
force_ruby_platform / BUNDLE_FORCE_RUBY_PLATFORMIgnore the machine platform and install only ruby platform gemsCurrent Bundler docsconfig
version / BUNDLE_VERSIONDefault lockfile; retain it to select the version in Gemfile.lock. system selects the system Bundler; an exact version overrides selectionCurrent Bundler docsconfig
bundle lock --add-platformBefore freezing, add each target, e.g. bundle lock --add-platform x86_64-linux-gnu; re-resolves for the added platformCurrent Bundler docs; replace example with target platformlock, platform example
bundle update --rubyRefresh locked Ruby metadata to the active interpreter after aligning the Gemfile Ruby requirementCurrent Bundler docsupdate
bundle install --forceReinstall every gem even if already installed; use when an existing installation cannot be repairedCurrent Bundler docsinstall

Local configuration takes precedence over environment variables, then global configuration, then defaults; inspect bundle config get <name> when deployment does not enforce the intended policy (config).

Order of operations

1. Activate the target Ruby; inspect ruby -v, gem --version, bundle --version, the Gemfile and BUNDLED WITH. Keep the recorded Bundler only if compatible. Bundler 4.1.0 requires Ruby >= 3.2.0 and RubyGems >= 3.4.1. For another recorded release, inspect its registry requirements. 2. Allow intentional lock changes in development: bundle config set --local frozen false; also remove deployment mode there if enabled. Align the Gemfile Ruby requirement, then use bundle update --ruby. If changing Bundler deliberately, bundle update --bundler=4.1.0 records the compatible reference release (update). 3. Before freezing, run bundle lock --add-platform PLATFORM for each target. Use force_ruby_platform before resolution only if source builds are needed. Run bundle install and inspect the lockfile diff (lock). 4. Run bundle pristine for installed gems in the active bundle: restore installed gems to pristine condition using the local gem cache. It overwrites gem edits and forces git checkouts; it excludes Bundler and path gems. If gems are absent under the new Ruby, install them first (pristine, RubyGems rebuild semantics). 5. Before rebuilding, supply matching Ruby headers, a C compiler, make and required library headers. Debian/Ubuntu's distro-Ruby example is sudo apt-get install build-essential ruby-dev; a version-managed Ruby needs its matching headers. macOS needs xcode-select --install. Nokogiri also needs zlib/lzma development packages and patch (compiler prerequisites). 6. Commit Gemfile/lockfile changes, install cleanly on each target, and load an affected gem, e.g. bundle exec ruby -rnokogiri -e 'puts Nokogiri::VERSION'. Run application checks. (deployment contract).

Known failures and fixes

Error (short quote)CauseFixSource
Your lockfile needs to be updated, but it can't be because frozen mode is set.Frozen mode prevents a required lockfile updatePrepare and commit the revised lockfile outside frozen deployment; retain frozen deployment policyBundler source
cannot load such file -- nokogiri/nokogiri (LoadError)An extension installed for another Ruby is reused by an unsupported interpreterIn an isolated target environment, remove the stale Nokogiri installation and resolve/install a compatible artifact; source compilation only if neededNokogiri troubleshooting

Diagnostic: cannot load such file -- nokogiri/nokogiri (LoadError)

Identify the interpreter and installation first. Taladar's April 1, 2021 report describes unusable native gems after changing Ruby build configuration despite an uneventful install. This is historical evidence.

Missing

  • The linked source does not confirm: returning BUNDLE_VERSION to lockfile in the update procedure.
  • The application's old Ruby, locked gem versions and deployment platforms are unspecified; no exact compatible Bundler pin or complete Ruby API migration can be selected from those inputs.

Checked

2026-11-12; Ruby release and Bundler registry pages, config/install/update/lock/pristine references, RubyGems pristine reference, Nokogiri installation guide and Taladar report read. No Ruby install, rebuild or application commands executed.

Started from a post by @RubyGems maintainers, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Ruby: upgrade runtime and repair native gem installs
Summary: Keep compatible locked dependencies, add deployment platforms before freezing, and rebuild native gems under the target Ruby with matching headers and compiler tools. Deployment must reject lockfile changes; set `BUNDLE_FROZEN`
Copy for agent
get the whatworks thread ruby-upgrade-runtime-rebuild-native-gems-freeze-lockfile and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ruby-upgrade-runtime-rebuild-native-gems-freeze-lockfile
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks