Currently there is no single place for packagers (or users) to configure both
gem and bundle to do user installs (e.g. ~/.local/share/gem/ruby/3.0.0). Setting
GEM_HOME to ~/.gem is one option, but then you would be mixing ruby versions,
and it's not the same location --user-install uses. Another option is
GEM_HOME=$(ruby -e 'puts Gem.user_dir'), but that is hardly user-friendly.

My last attempt to fix this was in pull request #4028, but that was closed
without any explanation as to what was wrong with the approach, or a way to move
forward.

This patch series expands on that previous attempt by introducing a
`Gem.user_install` method that distributions can override to enable this
feature. It's off by default.

If enabled all it does is switch the default installation path from
`Gem.default_dir` to `Gem.user_dir`.

This solution fixes all the problems.

Distributions can override this method and even do something fancy like
`Process.uid != 0`, which would enable user_install for users, but disable it
for root (thus tapering the need for --[no-]user-install). This could eventually
become the default for everyone.

If a user wants to install to `Gem.default_dir` all she has to do is
--no-user-install (I made sure that works).

In addition there's an environment variable GEM_USER_INSTALL that when set does
the same thing as `Gem.user_install`, but with it users don't need to depend on
their distribution package and can enable the feature themselves without doing
any convoluted GEM_HOME tricks.

Moreover, I found some issues with the interaction of --user-install and `gem
uninstall`, which I've fixed.

You can find the branch here:

https://github.com/felipec/rubygems/tree/fc/user-install

And here is the diffstat:

  lib/rubygems/commands/environment_command.rb         |  5 +++++
  lib/rubygems/commands/uninstall_command.rb           |  2 +-
  lib/rubygems/defaults.rb                             |  8 ++++++++
  lib/rubygems/installer.rb                            | 20 ++++++++++++--------
  lib/rubygems/installer_test_case.rb                  | 12 ++++--------
  lib/rubygems/path_support.rb                         |  4 +++-
  lib/rubygems/test_case.rb                            |  2 +-
  lib/rubygems/uninstaller.rb                          | 17 ++++++++++++-----
  test/rubygems/test_gem.rb                            | 10 ++++++++++
  test/rubygems/test_gem_commands_uninstall_command.rb |  4 ++--
  test/rubygems/test_gem_installer.rb                  | 18 +++++++++---------
  test/rubygems/test_gem_uninstaller.rb                | 21 ++++++++++++++++++++-
  12 files changed, 87 insertions(+), 36 deletions(-)

I am sending here only a simplified version with the crucial stuff:
`Gem.user_install`.

Why am I sending this here? Because the maintainers of rubygems would rather
harm their users than hear my voice, so they blocked me from their GitHub
project.

I tried to make a pull request, and GitHub did not let me.

Any feedback is welcome.

Cheers.

[1] https://github.com/rubygems/rubygems/pull/4028

Felipe Contreras (2):
  Add Gem.user_install
  install: fix --[no-]user-install

 lib/rubygems/defaults.rb            | 8 ++++++++
 lib/rubygems/installer.rb           | 6 +++---
 lib/rubygems/installer_test_case.rb | 6 +++---
 lib/rubygems/path_support.rb        | 3 ++-
 4 files changed, 16 insertions(+), 7 deletions(-)

-- 
2.32.0.rc0


Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>