Skip to content

gem uninstall --user-install GEM_NAME throws InstallError, even if the gem is installed #6457

Closed
@duckinator

Description

@duckinator

Describe the problem as clearly as you can

If you run gem install --user-install SOME_GEM, then run gem uninstall --user-install SOME_GEM, RubyGems throws an error because the gem is not in GEM_HOME and tells you to use --install-dir instead.

There is a test which seems relevant, and passes. It does not catch this problem, however.

def test_uninstall_user_install
@user_spec = Gem::Specification.find_by_name "b"
uninstaller = Gem::Uninstaller.new(@user_spec.name,
:executables => true,
:user_install => true)
gem_dir = File.join @user_spec.gem_dir
Gem.pre_uninstall do
assert_path_exist gem_dir
end
Gem.post_uninstall do
assert_path_not_exist gem_dir
end
uninstaller.uninstall
assert_path_not_exist gem_dir
assert_same uninstaller, @pre_uninstall_hook_arg
assert_same uninstaller, @post_uninstall_hook_arg
end

I suspect we need something closer to an integration test, possibly in test/rubygems/test_gem_commands_uninstall_command.rb.

Did you try upgrading RubyGems?

Yes. This occurs both on RubyGems 3.4.8 and master (as of 6256829)

Post steps to reproduce the problem

Using Ruby 3.0.5p211, via the FreeBSD lang/ruby30 package.

$ gem --version
3.4.8
$ gem install --user-install boop
Fetching boop-0.5.0.gem
WARNING:  You don't have /home/puppy/.gem/ruby/3.0/bin in your PATH,
          gem executables will not run.
Successfully installed boop-0.5.0
1 gem installed
$ gem uninstall --user-install boop
ERROR:  While executing gem ... (Gem::InstallError)
    boop is not installed in GEM_HOME, try:
        gem uninstall -i /usr/home/puppy/.gem/ruby/3.0 boop
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/uninstaller.rb:124:in `uninstall'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/commands/uninstall_command.rb:195:in `uninstall'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/commands/uninstall_command.rb:181:in `uninstall_gem'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/commands/uninstall_command.rb:175:in `block in uninstall_specific'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/commands/uninstall_command.rb:167:in `each'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/commands/uninstall_command.rb:167:in `uninstall_specific'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/commands/uninstall_command.rb:133:in `execute'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/command.rb:327:in `invoke_with_build_args'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/command_manager.rb:252:in `invoke_command'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/command_manager.rb:192:in `process_args'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/command_manager.rb:150:in `run'
        /usr/local/lib/ruby/site_ruby/3.0/rubygems/gem_runner.rb:51:in `run'
        /usr/local/bin/gem:10:in `<main>'
puppy@orthrus.fox:~/test$

Which command did you run?

gem uninstall --user-install boop (exact gem does not matter).

What were you expecting to happen?

I was expecting it to uninstall the specified gem.

What actually happened?

It said it is not installed in GEM_HOME, and recommends using -i (--install-dir) with the user-install directory (the value of Gem.user_dir).

Run gem env and paste the output below

RubyGems Environment:
  - RUBYGEMS VERSION: 3.4.8
  - RUBY VERSION: 3.0.5 (2022-11-24 patchlevel 211) [amd64-freebsd13]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/3.0
  - USER INSTALLATION DIRECTORY: /home/puppy/.gem/ruby/3.0
  - RUBY EXECUTABLE: /usr/local/bin/ruby30
  - GIT EXECUTABLE: /usr/local/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /home/puppy/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - amd64-freebsd-13
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/3.0
     - /usr/home/puppy/.gem/ruby/3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => true
     - :bulk_threshold => 1000
     - "gem" => "--suggestions --no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/home/puppy/.rubies/ruby-3.2.1/lib/ruby/gems/3.2.0/bin
     - /home/puppy/.cargo/bin
     - /home/puppy/bin
     - /home/puppy/.local/bin
     - /home/puppy/.gem/ruby/bin
     - /home/puppy/.npm-global/bin
     - /home/puppy/go/bin
     - /bin
     - /usr/bin
     - /sbin
     - /usr/sbin
     - /usr/local/bin
     - /usr/local/sbin

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions