As a Mac user, Homebrew is a must-have to install development packages and keep them up-to-date. And with Homebrew Cask, it can install and update GUI applications, too. However, after a few years of usage and frequent updates, the number of packages installed has increased a lot. Some are due to added dependencies of installed packages, and some are left-over dependencies from packages that are no longer required.
To clean up the Homebrew installation, we need to identify unused packages that are not part of the dependency tree of other packages. Brew provides a few commands to list packages and dependencies:
brew listreturns all installed packages;
brew deps --installedreturns the dependencies for all installed packages, and
brew deps --installed --treeshows the dependencies in a nicer tree structure;
brew leavesreturns installed packages that are not dependencies of another installed package.
Therefore, packages that are part of
brew leaves but were not installed explicitly by us can be removed by
brew uninstall. As we remove packages, more leaf packages can surface, so make sure to repeatedly run
brew leaves after each uninstallation with
brew uninstall until there is no more unwanted leaf packages.