Bundler Reported GemNotFound for rdoc 8.1.0 Under Homebrew Ruby 4.0.9. The Gem Folder Was on Disk With No Gemspec.

RubyGems writes a gem's plugin file before its gemspec. Under Homebrew Ruby that plugin file is a symlink into the read-only Cellar. Read from source, a failed write there leaves the gem's files on disk with no gemspec, which was the state on my Mac on November 13.

On November 13, 2026, my Mac had a folder gems/rdoc-8.1.0 with 14 entries in it, and no specifications/rdoc-8.1.0.gemspec. To Bundler, a gem in that state is not installed.

My notes from November 10, 2026 record an earlier case. bundle install for my Flutter app's fastlane setup could not install rdoc (8.1.0) from Gemfile.lock, and Bundler reported GemNotFound. I do not have the verbatim message; the note names the error class only. The recorded cause was not a missing gem. It was EACCES on a small plugin file in a different directory (61 bytes when I looked on November 13), and it only happened because the command ran under a different Ruby than the one my terminal uses.

Two shells, two Rubies

The failing bundle install ran in an AI coding agent's shell. My note records that my terminal runs with RBENV_VERSION=3.4.1, where bundle check passed. The agent's shell had no such variable, my app's repository has no .ruby-version, and ~/.rbenv/version did not exist.

rbenv's README describes the three layers: rbenv global writes ~/.rbenv/version, and that version "can be overridden by an application-specific .ruby-version file, or by setting the RBENV_VERSION environment variable." What happens when all three are absent is clearer in rbenv's own scripts. This is libexec/rbenv-version-name in rbenv 1.3.2:

if [ -z "$RBENV_VERSION" ]; then
  RBENV_VERSION_FILE="$(rbenv-version-file)"
  RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
fi
# ...
if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
  echo "system"
  exit
fi

rbenv-version-file looks for .ruby-version from the current directory upward, and otherwise prints the global file's path, in the words of its header comment, "even if that file does not exist." So the order is the environment variable, then .ruby-version, then the global file, then system. The README says system means "the system Ruby (detected by searching your $PATH)." On November 13 the first ruby on PATH after the rbenv shims was /opt/homebrew/bin/ruby, Homebrew Ruby 4.0.9.

On November 13 the agent's shell printed system for rbenv version with no warning, and ruby -v succeeded. It answered with a different Ruby than my terminal did.

The file RubyGems could not open

Homebrew's Ruby ships rdoc 7.0.4 as a bundled gem, including a RubyGems plugin stub. In the linked prefix, that stub was a symlink into the Cellar on November 13 (owner and date columns trimmed):

ls -l /opt/homebrew/lib/ruby/gems/4.0.0/plugins/
ls -l /opt/homebrew/Cellar/ruby/4.0.9/lib/ruby/gems/4.0.0/plugins/
lrwxr-xr-x  rdoc_plugin.rb -> ../../../../../Cellar/ruby/4.0.9/lib/ruby/gems/4.0.0/plugins/rdoc_plugin.rb
-r--r--r--  61  rdoc_plugin.rb

The target was mode 444. The plugins directory that held the symlink was mode 755 and writable by me, so a check of the directory found nothing wrong.

Installing rdoc 8.1.0 has to rewrite that stub, because the file name is derived from the gem name, not the version. This is regenerate_plugins_for in rubygems/installer_uninstaller_utils.rb, RubyGems 4.0.23:

spec.plugins.each do |plugin|
  plugin_script_path = File.join plugins_dir, "#{spec.name}_plugin#{File.extname(plugin)}"

  File.open plugin_script_path, "wb" do |file|
    file.puts "require_relative '#{Pathname.new(plugin).relative_path_from(Pathname.new(plugins_dir))}'"
  end

File.open with "wb" opens the existing path for writing. It does not remove the path first, so the open goes through the symlink to the read-only file in the Cellar. That is where my note places the EACCES.

Why the gem ends up on disk but not installed

The order of operations is the whole story. Bundler does not call Gem::Installer#install directly; it subclasses it and overrides install. This is Bundler::RubyGemsGemInstaller#install in Bundler 4.0.23, trimmed:

SharedHelpers.filesystem_access(gem_dir, :write) do
  extract_files
end

build_extensions if spec.extensions.any?
write_build_info_file
run_post_build_hooks

SharedHelpers.filesystem_access(bin_dir, :write) do
  generate_bin
end

generate_plugins

write_spec

RubyGems' own install has the same order: extract_files, then generate_bin and generate_plugins, then write_spec. extract_files unpacks the gem into gems/rdoc-8.1.0. generate_plugins calls regenerate_plugins_for, which raises. write_spec, the one line that creates specifications/rdoc-8.1.0.gemspec, never runs.

Two details in that listing matter. The extract and the binstub steps are wrapped in filesystem_access, which can turn EACCES into Bundler's own permission error naming the path (it converts when the message names that path or the action is a create, and re-raises otherwise). generate_plugins is not wrapped. And RubyGems' install ends with rescue Errno::EACCES, re-raising it as Gem::FilePermissionError, but Bundler's override has no such clause.

Bundler then decides whether a gem is installed from the specifications side. In bundler/source/rubygems.rb:

def installed?(spec)
  installed_specs[spec].any? && !spec.installation_missing?
end

installed_specs is built from Gem::Specification.stubs, which are the gemspec files. A folder under gems/ with no gemspec contributes nothing to it. When locked gems are missing at materialization, bundler/definition.rb raises the error my note names:

raise GemNotFound, "Could not find #{missing_specs_list.join(" nor ")}"

This last link is an inference. I read that the code path exists; my note does not say which command printed GemNotFound, or whether an EACCES line appeared before it.

Someone else's log shows the EACCES half of that. It shows a raw Errno::EACCES during the install and no GemNotFound, so it does not show the second half. In ruby/rubygems#9790, opened August 20, 2026, a bundle update fastlane under Homebrew Ruby 4.0.5 stops at Installing rdoc 8.0.0 with this (trimmed):

Errno::EACCES: Permission denied @ rb_sysopen - /opt/homebrew/lib/ruby/gems/4.0.0/plugins/rdoc_plugin.rb
  .../rubygems/installer_uninstaller_utils.rb:16:in 'File#initialize'
  ...
  .../bundler/rubygems_gem_installer.rb:79:in 'Bundler::RubyGemsGemInstaller#generate_plugins'

That issue was closed as not planned the next day, with a maintainer's reply that it is "a filesystem permission issue, not a RubyGems bug." A commenter there traced it to the Cellar symlink and pointed to Homebrew/homebrew-core#261905, a report about gem pristine --all failing on the same read-only files. One reply there calls the directory of gems that ship with Ruby "supposed to be immutable", and another names rdoc_plugin.rb among the files that a permissions fix would have to make writable. That issue is also closed as not planned. So the behavior is known on both sides, and when I read the two threads on November 13, neither project had a change planned.

A read-only check

This block changes nothing. It prints which Ruby the current shell resolves and why, lists gem folders that have no gemspec, and flags plugin stubs that are symlinks or not writable.

command -v ruby; ruby -v
rbenv version
echo "RBENV_VERSION=${RBENV_VERSION:-unset}"
ls ~/.rbenv/version .ruby-version

G="$(gem env home)"
for d in "$G"/gems/*/; do
  n=$(basename "$d")
  [ -e "$G/specifications/$n.gemspec" ] || [ -e "$G/specifications/default/$n.gemspec" ] || echo "no gemspec: $n"
done
for p in "$G"/plugins/*; do
  [ -L "$p" ] && echo "symlink: $p -> $(readlink "$p")"
  [ -w "$p" ] || echo "not writable: $p"
done

Output from the agent's shell on November 13, 2026, with my home directory shortened:

~/.rbenv/shims/ruby
ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin25]
system
RBENV_VERSION=unset
ls: .ruby-version: No such file or directory
ls: ~/.rbenv/version: No such file or directory
no gemspec: cgi-0.5.2
no gemspec: io-console-0.9.5
no gemspec: rdoc-8.1.0
symlink: /opt/homebrew/lib/ruby/gems/4.0.0/plugins/rdoc_plugin.rb -> ../../../../../Cellar/ruby/4.0.9/lib/ruby/gems/4.0.0/plugins/rdoc_plugin.rb
not writable: /opt/homebrew/lib/ruby/gems/4.0.0/plugins/rdoc_plugin.rb

Run it in each shell you care about: your terminal, your editor's task runner, your agent. If the first four lines differ between them, you have my November 10 setup.

The rest of that output does not match my note. My note says that on November 10 the half-installed rdoc-8.1.0, cgi-0.5.2, io-console-0.9.5 and erb-6.0.7 folders were moved to the Trash, and that rbenv global 3.4.1 was run so that shells without the variable would get 3.4.1. Three days later the global file was absent and all four folder names were back, dated November 13, 12:01. erb-6.0.7 had a default gemspec on November 13, so the check listed only the other three. I have no record of what removed the file or which command recreated the folders, so I am reporting the state and not a cause. Later the same day I set the global default again, moved the three folders without a gemspec to the Trash, and opened a pull request that adds a .ruby-version file to the app's repository.

Of those folders, only rdoc's has a rubygems_plugin.rb in lib/. The cgi and io-console folders have an ext/ directory and no plugin file, and I have not established why they are left without a gemspec.

What to pin, and what not to work around

There are three places to say "this project uses Ruby 3.4.1", and they fail differently.

A global default (rbenv global) is what my record chose. It covers every shell and every repository with one command. The strongest argument against it is the output above: it is one unversioned file in my home directory, and when it is missing rbenv falls back to system without a word.

A .ruby-version in the repository is checked before the global file, travels with the code, and is visible in review. The reason to choose otherwise is that it binds everyone who clones the repository to one patch version, which is a cost if contributors or CI images do not have exactly that one installed.

A prefix on each command (RBENV_VERSION=3.4.1 bundle install) is my record's fallback rule for when ruby -v shows 4.0.9 again. It needs nothing on disk, and it depends on every caller remembering it.

The second decision is whether to make the install succeed under Homebrew Ruby instead. A commenter on the RubyGems issue reports that bundle config set --local path vendor/bundle got them past it. RubyGems derives the plugins directory from the gem home (@plugins_dir = Gem.plugindir(@gem_home)), so my reading, which I did not test, is that the stub is then written inside the project. My note says not to use a BUNDLE_PATH workaround and not to run bundle install under Homebrew Ruby in that repository; it does not record a reason. The case for the workaround is strong: it is one line, it is local to the project, and it stops writing project gems into a package manager's prefix. What it does not change is that the two shells would still run one Gemfile.lock on two different Rubies, 3.4.1 and 4.0.9.

Limits

This is one Mac, observed on November 10 and November 13, 2026. The source I quoted is from Homebrew Ruby 4.0.9 with RubyGems 4.0.23 and Bundler 4.0.23, Homebrew 7.0.13, rbenv 1.3.2 and macOS 26.7.3, all read on November 13. The November 10 note records Ruby 4.0.9 and 3.4.1 but not the RubyGems or Bundler versions of that day. On November 27 Homebrew Ruby was 4.0.10 with RubyGems and Bundler 4.1.0, and the plugin write and the install order quoted above were unchanged.

I did not reproduce the failure for this article. The mechanism is read from source and matched against the state on disk and against another person's backtrace from Ruby 4.0.5 with Bundler 4.0.8. The step from "no gemspec" to GemNotFound is read from Bundler's code and is not tied to a captured message of mine.

I did not test vendor/bundle, and I did not test the fix another commenter reports, a gem install rdoc -v 7.2.0 that left the stub as a regular file. Other version managers have their own fallback rules, and I checked only rbenv.