From 33bd95625756562f4865fbc6ad5c39e0cfbc26d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 1 Dec 2023 12:53:43 +0100 Subject: [rubygems/rubygems] Better approach to falling back to user installation when GEM_HOME not writable https://github.com/rubygems/rubygems/commit/f67bced16b --- lib/rubygems/installer.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lib/rubygems/installer.rb') 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 -- cgit v1.2.3