卸载删除Homebrew包,包括其所有依赖项

    技术2025-10-26  11

    本文翻译自:Uninstall / remove a Homebrew package including all its dependencies

    I have a Homebrew package that I wish to uninstall / remove with all its dependencies, skipping packages whom other packages depend upon. 我有一个Homebrew包,我希望卸载/删除所有依赖项,跳过其他包依赖的包。

    eg Uninstall package a which depends on packages b & c , where package d also depends on package c . 例如,卸载包a ,这取决于包b和c ,其中包d也取决于包c 。 The result should uninstall both a & b , skipping c . 结果应该同时卸载a & b ,跳过c 。

    How can I do that? 我怎样才能做到这一点?

    There must be a way to uninstall a package without leaving unnecessary junk behind. 必须有一种方法来卸载包,而不会留下不必要的垃圾 。


    #1楼

    参考:https://stackoom.com/question/Uj77/卸载-删除Homebrew包-包括其所有依赖项


    #2楼

    您可以使用UNIX管道

    brew deps [FORMULA] | xargs brew rm

    #3楼

    Using this answer requires that you create and maintain a file that contains the package names you want installed on your system. 使用此答案需要您创建和维护包含要在系统上安装的软件包名称的文件。 If you don't have one already, use the following command and delete the package names what you don't want to keep installed. 如果您还没有,请使用以下命令并删除您不想继续安装的软件包名称。

    brew leaves > brew_packages

    Then you can remove all installed, but unwanted packages and any unnecessary dependencies by running the following command 然后,您可以通过运行以下命令来删除所有已安装但不需要的软件包以及任何不必要的依赖项

    brew_clean brew_packages

    brew_clean is available here: https://gist.github.com/cskeeters/10ff1295bca93808213d brew_clean可在此处获取: https : brew_clean

    This script gets all of the packages you specified in brew_packages and all of their dependancies and compares them against the output of brew list and finally removes the unwanted packages after verifying this list with the user. 此脚本获取您在brew_packages中指定的所有包及其所有依赖项,并将它们与brew list的输出进行比较,最后在与用户验证此列表后删除不需要的包。

    At this point if you want to remove package a , you simply remove it from the brew_packages file then re-run brew_clean brew_packages . 此时如果要删除包a ,只需将其从brew_packages文件中删除,然后重新运行brew_clean brew_packages 。 It will remove b , but not c . 它会删除b ,但不会删除c 。


    #4楼

    The goal here is to remove the given package and its dependencies without breaking another package's dependencies. 这里的目标是删除给定的包及其依赖项, 而不会破坏另一个包的依赖项。 I use this command: 我用这个命令:

    brew deps [FORMULA] | xargs brew remove --ignore-dependencies && brew missing | xargs brew install

    Note: Edited to reflect @alphadogg's helpful comment. 注意:编辑反映@ alphadogg的有用评论。


    #5楼

    Based on @jfmercer answer (corrections needed more than a comment). 基于@jfmercer的答案(更正需要的不仅仅是评论)。

    Remove package's dependencies (does not remove package): 删除包的依赖项(不删除包):

    brew deps [FORMULA] | xargs brew remove --ignore-dependencies

    Remove package: 删除包:

    brew remove [FORMULA]

    Reinstall missing libraries: 重新安装缺少的库:

    brew missing | cut -d: -f2 | sort | uniq | xargs brew install

    Tested uninstalling meld after discovering MeldMerge releases . 在发现MeldMerge版本后测试卸载meld 。


    #6楼

    brew rmtree doesn't work at all . brew rmtree 根本不起作用 。 From the links on that issue I found rmrec which actually does work. 从这个问题的链接我发现rmrec实际上工作。 God knows why brew doesn't have this as a native command. 上帝知道为什么brew没有这个作为本土命令。

    brew tap ggpeti/rmrec brew rmrec pkgname
    Processed: 0.009, SQL: 9