Homebrew: uninstall unneeded dependencies

While dealing with setting up my new MacBook Pro with Apple Silicon M1 Pro chip I chose not to use the image from my older MacBook Pro 2015. I decided to install everything I need from scratch.

I encountered the problem with uninstalling brew packages and all their dependencies that are not needed by another packages. Maybe it is not a problem, but just nice to know practice.

Firstly I thought I will need gcc so I typed:

➜  ~ brew install gcc

Installing gcc package resulted with installing a few dependences under the hood

➜  ~ brew deps --tree --installed gcc
gcc
├── gmp
├── isl
│   └── gmp
├── libmpc
│   ├── gmp
│   └── mpfr
│       └── gmp
├── mpfr
│   └── gmp
└── zstd

After a while I decided I don’t need gcc so I installed it with

➜  ~ brew uninstall gcc

But some dependencies were not removed along with gcc. The best suggestion I found (here) to list them and remove is to use brew autoremove command.

With option -n you can list unneeded dependencies that could be uninstalled:

➜  ~ brew autoremove -n
==> Would uninstall 4 unneeded formulae:
isl
libmpc
mpfr
zstd

and execute brew autoremove to uninstall them

➜  ~ brew autoremove
==> Uninstalling 4 unneeded formulae:
isl
libmpc
mpfr
zstd
Uninstalling /opt/homebrew/Cellar/zstd/1.5.1... (31 files, 2.4MB)
Uninstalling /opt/homebrew/Cellar/isl/0.24... (73 files, 7MB)
Uninstalling /opt/homebrew/Cellar/libmpc/1.2.1... (12 files, 415.7KB)
Uninstalling /opt/homebrew/Cellar/mpfr/4.1.0... (30 files, 5.2MB)

Thanks for reading. Do you know any better solution? Don’t hesitate to leave a comment!

Leave a comment

Your email address will not be published.