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.
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
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
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.