diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 1fe6f36f38..00dc5707c3 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -235,6 +235,18 @@ module Gem default_cert_path end + ## + # Enables automatic installation into user directory + + def self.default_user_install # :nodoc: + if !ENV.key?("GEM_HOME") && (File.exist?(Gem.dir) && !File.writable?(Gem.dir)) + Gem.ui.say "Defaulting to user installation because default installation directory (#{Gem.dir}) is not writable." + return true + end + + false + end + ## # Install extensions into lib as well as into the extension directory. diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index cd1031dc2e..0396e94632 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -684,10 +684,7 @@ class Gem::Installer # * `true`: `--user-install` # * `false`: `--no-user-install` and # * `nil`: option was not specified - if options[:user_install] - @gem_home = Gem.user_dir - elsif options[:user_install].nil? && !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." + if options[:user_install] || (options[:user_install].nil? && Gem.default_user_install) @gem_home = Gem.user_dir end end