Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstall / remove a Homebrew package including all its dependencies

Tags:

macos

homebrew

I have a Homebrew formula that I wish to uninstall/remove along with all its dependencies, skipping packages whom other packages depend upon (a.k.a. Cascading package removal in Package manager parlance).

e.g. Uninstall package a which depends on packages b & c, where package d also depends on package c. The result should uninstall both a & b, skipping c.

How can I do that?

There must be a way to uninstall a package without leaving unnecessary junk behind.

like image 359
Ory Band Avatar asked Sep 06 '11 16:09

Ory Band


People also ask

Does brew uninstall remove dependencies?

For instance, when you do brew install git , you add git executable and gettext and pcre2 as dependencies. Unfortunately, when you reverse this process with brew uninstall git , the main formula disappears, but you end up with two no longer needed dependencies.

How do I uninstall a Mac package?

On your Mac, click the Finder icon in the Dock, then click Applications in the Finder sidebar. Do one of the following: If an app is in a folder: Open the app's folder to check for an Uninstaller. If Uninstall [App] or [App] Uninstaller is shown, double-click it, then follow the onscreen instructions.

How do I remove a package from dependencies?

To remove a dev dependency, you need to attach the -D or --save-dev flag to the npm uninstall, and then specify the name of the package. You must run the command in the directory (folder) where the dependency is located.


2 Answers

EDIT:

It looks like the issue is now solved using an external command called brew rmdeps or brew rmtree.

To install and use, issue the following commands:

$ brew tap beeftornado/rmtree $ brew rmtree <package> 

See the above link for more information and discussion.


[EDIT] see the new command brew autoremove in https://stackoverflow.com/a/66719581/160968


Original answer:

It appears that currently, there's no easy way to accomplish this.

However, I filed an issue on Homebrew's GitHub page, and somebody suggested a temporary solution until they add an exclusive command to solve this.

There's an external command called brew leaves which prints all packages that are not dependencies of other packages.

If you do a logical and on the output of brew leaves and brew deps <package>, you might just get a list of the orphaned dependency packages, which you can uninstall manually afterwards. Combine this with xargs and you'll get what you need, I guess (untested, don't count on this).


EDIT: Somebody just suggested a very similar solution, using join instead of xargs:

brew rm FORMULA brew rm $(join <(brew leaves) <(brew deps FORMULA)) 

See the comment on the issue mentioned above for more info.

like image 115
7 revs, 5 users 57% Avatar answered Sep 18 '22 19:09

7 revs, 5 users 57%


By the end of 2020, the Homebrew team added a simple command brew autoremove to remove all unused dependencies.

First, uninstall the package:

brew uninstall <package>

Then, remove all the unused dependencies:

brew autoremove

like image 41
hsym Avatar answered Sep 21 '22 19:09

hsym