ruby/rubygems · error · Gem::FilePermissionError
You don't have write permissions for the #{directory} direct
Error message
You don't have write permissions for the #{directory} directory. What it means
Error "You don't have write permissions for the #{directory} directory." thrown in ruby/rubygems.
Source
Thrown at lib/rubygems/installer.rb:313
end
write_spec
write_cache_file
File.chmod(dir_mode, gem_dir) if dir_mode
say clean_text(spec.post_install_message.to_s) if options[:post_install_message] && !spec.post_install_message.nil?
Gem::Specification.add_spec(spec) unless @install_dir
load_plugin unless options[:install_plugin] == false
run_post_install_hooks
spec
rescue Errno::EACCES => e
# Permission denied - /path/to/foo
raise Gem::FilePermissionError, e.message.split(" - ").last
end
def run_pre_install_hooks # :nodoc:
Gem.pre_install_hooks.each do |hook|
next unless hook.call(self) == false
location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/
message = "pre-install hook#{location} failed for #{spec.full_name}"
raise Gem::InstallError, message
end
end
def run_post_build_hooks # :nodoc:
Gem.post_build_hooks.each do |hook|
next unless hook.call(self) == false
FileUtils.rm_rf gem_dir
location = " at #{$1}" if hook.inspect =~ /[ @](.*:\d+)/View on GitHub (pinned to 86cbb817a3)
Solutions
- Install into your user directory: `gem install --user-install <gem>`
- Fix ownership/permissions of the gem directory, or use sudo for system installs
When it happens
Trigger: Thrown at lib/rubygems/installer.rb:313 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ruby/rubygems@86cbb817a3 (2026-08-23).
Data as JSON: /api/errors/fc1db3fe55c6ac0c.
Report an issue: GitHub.