summaryrefslogtreecommitdiff
path: root/lib/rubygems/installer.rb
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2023-12-01 12:53:43 +0100
committerHiroshi SHIBATA <[email protected]>2023-12-07 13:56:22 +0900
commit33bd95625756562f4865fbc6ad5c39e0cfbc26d6 (patch)
treeab0a3ade84487022e7fd92b09e61fb9139d2f591 /lib/rubygems/installer.rb
parent0f3f907e17bba1b94c5e202cb57988af8c6c91fc (diff)
[rubygems/rubygems] Better approach to falling back to user installation when GEM_HOME not writable
https://github.com/rubygems/rubygems/commit/f67bced16b
Diffstat (limited to 'lib/rubygems/installer.rb')
-rw-r--r--lib/rubygems/installer.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index aca42a03b0..18170230df 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -676,7 +676,14 @@ class Gem::Installer
@build_args = options[:build_args]
@gem_home = @install_dir
- @gem_home ||= options[:user_install] ? Gem.user_dir : Gem.dir
+ @gem_home ||= if options[:user_install]
+ Gem.user_dir
+ elsif !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir))
+ say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable."
+ Gem.user_dir
+ else
+ Gem.dir
+ end
# If the user has asked for the gem to be installed in a directory that is
# the system gem directory, then use the system bin directory, else create