我是否必须手动卸载所有依赖宝石?

时间:2009-06-04 20:14:04

标签: ruby-on-rails ruby rubygems dependencies

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

但似乎还需要卸载一大堆依赖宝石。

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)

我尝试查找“gem uninstall”的文档,但似乎没有办法自动卸载依赖项:

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:\>

我错过了什么吗?

9 个答案:

答案 0 :(得分:31)

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

答案 1 :(得分:11)

据我所知你是对的,没有一种简单的方法可以内置到gem命令来执行此操作。

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

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

答案 2 :(得分:7)

我最终做了一个简单的command line tool to gem uninstall dependencies recursively

我还向gem uninstall dependencies recursively提交了一个rubygems问题。


该rubygems问题已经关闭,在有人提供包含测试的补丁之前不会考虑。

答案 3 :(得分:5)

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`

答案 4 :(得分:5)

运行这些卸载时的问题是它们按顺序排列在宝石列表中,因此如果可以卸载口音,那么最终会卡住。运行以下几次,它应该删除允许的所有宝石。

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

答案 5 :(得分:4)

gem cleanup应该做到这一点。有关详细信息,请参阅here

答案 6 :(得分:1)

这段代码为我做了:

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

答案 7 :(得分:0)

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

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

上面的命令会删除名称以" opener - "开头的所有宝石。

答案 8 :(得分:-1)

只需列出您要卸载的所有宝石,例如gem uninstall dm-migrations dm-cli dm-observer。并尝试尽可能使用Bundler管理您的宝石。