[#122973] [PATCH] Add Gem.default_install — Felipe Contreras via ruby-core <ruby-core@...>
We need a way to enable user installs by default so that tools like
3 messages
2025/08/17
[ruby-core:122973] [PATCH] Add Gem.default_install
From:
Felipe Contreras via ruby-core <ruby-core@...>
Date:
2025-08-17 20:00:38 UTC
List:
ruby-core #122973
We need a way to enable user installs by default so that tools like
bundler don't attempt to install to system directories.
The configuration Gem.default_user_install was meant to enable user
installs, but it only affects `gem install`, not bundler. Distributions
were already able to change the defaults of `gem install`, so it didn't
change anything, and that's why nobody is using it.
Instead we need a method that allows something that is not currently
possible: override Gem.dir.
Gem.default_install is that method, which allows changing user installs
to both gem and bundler.
It defaults to Gem.default_dir, so there's no change in functionality:
def default_install
default_dir
end
Distributions can then override this to enable user installs by default:
def default_install
user_dir
end
This allows for more flexibility than Gem.default_user_install. For
example distributions can choose to install to different directories
based on the user id:
def default_install
Process.uid == 0 ? local_dir : user_dir
end
The current Gem.default_user_install solution is simply not enough.
---
lib/rubygems/defaults.rb | 7 +++++++
lib/rubygems/path_support.rb | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb
index db07681a17..20f4fcd2f3 100644
--- a/lib/rubygems/defaults.rb
+++ b/lib/rubygems/defaults.rb
@@ -9,6 +9,13 @@ module Gem
@pre_uninstall_hooks ||= []
@pre_install_hooks ||= []
+ ##
+ # Determines the default install directory
+
+ def self.default_install
+ default_dir
+ end
+
##
# An Array of the default sources that come with RubyGems
diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb
index 13091e29ba..455f413f3d 100644
--- a/lib/rubygems/path_support.rb
+++ b/lib/rubygems/path_support.rb
@@ -24,7 +24,7 @@ class Gem::PathSupport
# hashtable, or defaults to ENV, the system environment.
#
def initialize(env)
- @home = normalize_home_dir(env["GEM_HOME"] || Gem.default_dir)
+ @home = normalize_home_dir(env["GEM_HOME"] || Gem.default_install)
@path = split_gem_path env["GEM_PATH"], @home
@spec_cache_dir = env["GEM_SPEC_CACHE"] || Gem.default_spec_cache_dir
--
0.1
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/