Do I have to manually uninstall all dependent gems?

前端 未结 9 2157
名媛妹妹
名媛妹妹 2020-12-08 06:50

I tried to uninstall datamapper using the command gem uninstall dm-core.

But it seems that a whole bunch of dependent gems also need to be uninstalled.

相关标签:
9条回答
  • 2020-12-08 07:19

    The problem when running these sort of uninstalls is that they go down the list of gems in order so if a gum is uninstallable then you end up getting stuck. Run the below a few times and it should remove all the gems it is allowed to.

    gem list | cut -d" " -f1 | sort -R | xargs -n1 gem uninstall -aIx
    
    0 讨论(0)
  • 2020-12-08 07:23

    This snippet of code does it for me:

    def gem_deps(name)
      if `gem dependency #{name}` =~ /(Gem #{name}-.*?)(Gem|\z)/m
        $1.split("\n").grep(/runtime\s*\)/).map do |line|
          line[/[\w-]+/]
        end.compact
      else
        []
      end
    end
    
    def gem_recursive_uninstall(name)
      deps = gem_deps(name)
      if deps.empty?
        system('sudo','gem','uninstall',name)
      else
        puts("Uninstall #{name} with dependencies: #{deps.join(', ')}? [y/n]")
        if gets.chomp[/y/]
          system(*(%w{sudo gem uninstall} + [name] + deps))
        end
      end
    end
    

    Taken from http://github.com/cldwalker/irbfiles/blob/master/.irb/libraries/gem.rb

    0 讨论(0)
  • 2020-12-08 07:25

    I ended up making a simple command line tool to gem uninstall dependencies recursively.

    I also filed a rubygems issue to gem uninstall dependencies recursively.


    That rubygems issue was closed and will not be considered until somebody provides a patch including tests.

    0 讨论(0)
提交回复
热议问题