我必须手动卸载所有依赖的gem?

我试图用命令gem uninstall dm-core卸载datamapper。

但是似乎还有一大堆依赖的gem需要卸载。

 C:\>gem uninstall dm-core You have requested to uninstall the gem: dm-core-0.9.11 dm-migrations-0.9.11 depends on [dm-core (= 0.9.11)] dm-cli-0.9.11 depends on [dm-core (= 0.9.11)] dm-serializer-0.9.11 depends on [dm-core (= 0.9.11)] dm-timestamps-0.9.11 depends on [dm-core (= 0.9.11)] dm-aggregates-0.9.11 depends on [dm-core (= 0.9.11)] dm-types-0.9.11 depends on [dm-core (= 0.9.11)] dm-is-tree-0.9.11 depends on [dm-core (= 0.9.11)] dm-observer-0.9.11 depends on [dm-core (= 0.9.11)] dm-validations-0.9.11 depends on [dm-core (= 0.9.11)] If you remove this gems, one or more dependencies will not be met. Continue with Uninstall? [Yn] n ERROR: While executing gem ... (Gem::DependencyRemovalException) Uninstallation aborted due to dependent gem(s) 

我试图find关于“gem卸载”的文档,但似乎没有办法自动卸载依赖关系:

 C:\>gem help uninstall Usage: gem uninstall GEMNAME [GEMNAME ...] [options] Options: -a, --[no-]all Uninstall all matching versions -I, --[no-]ignore-dependencies Ignore dependency requirements while uninstalling -x, --[no-]executables Uninstall applicable executables with out confirmation -i, --install-dir DIR Directory to uninstall gem from -n, --bindir DIR Directory to remove binaries from --[no-]user-install Uninstall from user's home directory in addition to GEM_HOME. -v, --version VERSION Specify version of gem to uninstall --platform PLATFORM Specify the platform of gem to uninst all Common Options: -h, --help Get help on this command -V, --[no-]verbose Set the verbose level of output -q, --quiet Silence commands --config-file FILE Use this config file instead of defau lt --backtrace Show stack backtrace on errors --debug Turn on Ruby debugging Arguments: GEMNAME name of gem to uninstall Summary: Uninstall gems from the local repository Defaults: --version '>= 0' --no-force --install-dir C:/Ruby18/lib/ruby/gems/1.8 --user-install C:\> 

我错过了什么吗?

据我所知你是正确的,有没有一种简单的方法内置到gem命令来做到这一点。

但是,您可以在删除dm-core之后查看可以帮助清理您的gem存储库的gem-prune。

http://github.com/ddollar/gem-prune/tree/master

gem list | cut -d" " -f1 | xargs gem uninstall -aIx gem list | cut -d" " -f1 | xargs gem uninstall -aIx删除所有已安装的ruby!

我结束了一个简单的命令行工具来gemrecursion卸载依赖关系 。

我也提交了一个rubygems问题,以recursion地卸载依赖关系 。


那个rubygems问题已经closures了,直到有人提供包含testing的补丁才会被考虑。

 for gem in `gem list --no-version`; do gem uninstall -aIx $gem done 

为我工作最好,不知道为什么

 gem list | cut -d" " -f1 | xargs gem uninstall -aIx 

不能在我的系统上工作,因为它仍然抱怨…

 ERROR: While executing gem ... (Gem::InstallError) cannot uninstall, check `gem list -d some-gem-here` 

运行这些卸载的问题是,他们顺序排列在gem列表中,所以如果一个口香糖是可卸载的,那么你最终会陷入困境。 运行下面的几次,它应该删除所有允许的gem。

 gem list | cut -d" " -f1 | sort -R | xargs -n1 gem uninstall -aIx 

gem cleanup应该做的伎俩。 详情请看这里 。

这段代码对我来说是这样的:

 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 

取自http://github.com/cldwalker/irbfiles/blob/master/.irb/libraries/gem.rb

只需列出您想要卸载的所有gem,例如gem uninstall dm-migrations dm-cli dm-observer 。 尽量用Bundlerpipe理你的gem。

如果你想使用一些通配符来删除一些gem(例如,从特定的供应商中删除一些gem),那么你可以将输出从gem列表输出到grep,如下所示

 gem list --no-version | grep "opener-" | cut -d " " -f1 | xargs gem uninstall -aIx 

以上命令将删除名称以“opener-”开头的所有gem