Skip to content

Can't uninstall gems installed with --user-install if /usr/local/lib/ruby/gems/3.4.0 does not exist #9149

Closed

Description

@classy-crustacean

I am using an Intel Macbook, and I installed ruby through Homebrew.

I never installed any gems without the --user-install flag. I installed boop: gem install --user-install boop

Then I tried uninstalling boop: gem uninstall --user-install boop
I got the following output:

ERROR:  While executing gem ... (Errno::ENOENT)
    No such file or directory @ rb_check_realpath_internal - /usr/local/lib/ruby/gems/3.4.0
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/uninstaller.rb:52:in 'File.realpath'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/uninstaller.rb:52:in 'Gem::Uninstaller#initialize'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/commands/uninstall_command.rb:202:in 'Class#new'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/commands/uninstall_command.rb:202:in 'Gem::Commands::UninstallCommand#uninstall'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/commands/uninstall_command.rb:188:in 'Gem::Commands::UninstallCommand#uninstall_gem'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/commands/uninstall_command.rb:183:in 'block in Gem::Commands::UninstallCommand#uninstall_specific'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/commands/uninstall_command.rb:175:in 'Array#each'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/commands/uninstall_command.rb:175:in 'Gem::Commands::UninstallCommand#uninstall_specific'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/commands/uninstall_command.rb:136:in 'Gem::Commands::UninstallCommand#execute'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/command.rb:326:in 'Gem::Command#invoke_with_build_args'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/command_manager.rb:253:in 'Gem::CommandManager#invoke_command'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/command_manager.rb:194:in 'Gem::CommandManager#process_args'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/command_manager.rb:152:in 'Gem::CommandManager#run'
	/usr/local/Cellar/ruby/3.4.7/lib/ruby/3.4.0/rubygems/gem_runner.rb:57:in 'Gem::GemRunner#run'
	/usr/local/opt/ruby/bin/gem:12:in '<main>'

Then I tried creating the /usr/local/lib/ruby/gems/3.4.0 directory and didn't put anything in it. I was able to successfully uninstall boop from by user directory.

Is there a way to be able to uninstall user-installed gems without creating /usr/local/lib/ruby/gems/3.4.0? I know /usr/local/lib/ruby/gems/3.4.0 is automatically created when installing gems without --user-install, but it seems weird to me that uninstalling user-installed gems is not possible without first installing a gem globally.

Make sure you're using the latest version of both RubyGems by running gem update --system.

Here is my gem env output:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.7.2
  - RUBY VERSION: 3.4.7 (2025-10-08 patchlevel 58) [x86_64-darwin23]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/3.4.0
  - USER INSTALLATION DIRECTORY: /Users/joseph.rosloniec/.gem/ruby/3.4.0
  - CREDENTIALS FILE: /Users/joseph.rosloniec/.local/share/gem/credentials
  - RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/lib/ruby/gems/3.4.0/bin
  - SPEC CACHE DIRECTORY: /Users/joseph.rosloniec/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/3.4.7/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-darwin-23
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/3.4.0
     - /Users/joseph.rosloniec/.gem/ruby/3.4.0
     - /usr/local/Cellar/ruby/3.4.7/lib/ruby/gems/3.4.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => true
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/joseph.rosloniec/.user-python-env/bin
     - /Users/joseph.rosloniec/.gem/ruby/3.4.0/bin
     - /usr/local/opt/ruby/bin
     - /usr/local/bin
     - /System/Cryptexes/App/usr/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
     - /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
     - /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin

Activity

  1. classy-crustacean commented on Dec 2, 2025

    @classy-crustacean
    Author

    I looked through the gem uninstall --help, and it looks like I could achieve this by using --install-dir DIR. However, it would be really nice if I didn't have to do that. Is there a reason the uninstaller could't check the user gem path if the normal gem path does not exist?

  2. tenderlove commented on Dec 3, 2025

    @tenderlove
    Member

    Is there a reason the uninstaller could't check the user gem path if the normal gem path does not exist?

    I don't think so. This seems like just a bug, and it should be fixed. I think something like this would do it (but I haven't tested):

    diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb
    index fe4c3a80cf..bffce04087 100644
    --- a/lib/rubygems/uninstaller.rb
    +++ b/lib/rubygems/uninstaller.rb
    @@ -64,7 +64,8 @@ def initialize(gem, options = {})
         @gem                = gem
         @version            = options[:version] || Gem::Requirement.default
         @install_dir        = options[:install_dir]
    -    @gem_home           = File.realpath(@install_dir || Gem.dir)
    +    @gem_home           = @install_dir || Gem.dir
    +    @gem_home = File.exist?(@gem_home) ? File.realpath(@gem_home) : nil
         @user_dir           = File.exist?(Gem.user_dir) ? File.realpath(Gem.user_dir) : Gem.user_dir
         @force_executables  = options[:executables]
         @force_all          = options[:all]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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