Uninstall Packages with Homebrew: The Homebrew command is the underlying package manager that installs all those UNIX and open-source utilities you might want. It’s the easiest way to install them on Mac OS X, just as it is on Linux. Like Homebrew Cask, it uses simple commands. To search for a utility
- A 64-bit Intel CPU
- macOS High Sierra (10.13) (or higher)
- Command Line Tools (CLT) for Xcode: xcode-select –install, developer.apple.com/downloads or Xcode
- A Bourne-compatible shell for installation (e.g. bash or zsh)
If you have installed Homebrew on a Mac to use as a package manager for various unix and command line utilities, you’ve probably also installed a handful of packages deemed useful to you. But what if you no longer need one, and you want to remove a particular Homebrew package?
It turns out that uninstalling packages / formula with Homebrew is very easy, and uninstalling and removing packages from Homebrew is just as easy as installing them in the first place.
we’re just talking about removing particular packages from Homebrew.
How to Uninstall & Remove Homebrew Packages
The proper way to remove a Homebrew package is with the uninstall or remove command.
The uninstall Homebrew package command looks like this:
brew uninstall packageName
The remove Homebrew package command looks like this:
brew remove packageName
As you may have guessed by now, the remove and uninstall commands are exactly the same, and get the same result; the removal of the Homebrew package.
For example, to remove and uninstall Telnet (assuming you installed telnet on the Mac with Homebrew anyway), you would use the following command string:
brew uninstall telnet
Or you can use the remove command for the same effect:
brew remove telnet
Removing a package from Homebrew is quick, as there is no need to download anything, it just deletes the Homebrew package from the Mac.
You can confirm the package was removed by trying to run the command again, or by checking where Homebrew packages are installed to and you will find the package you removed is no longer there.
Additional Homebrew Package Uninstall Options
There are two flags you can pass to the Homebrew uninstall command as well; –force and –ignore-dependencies.
The –force flag (or -f) will forcibly remove the package along with deleting all versions of that package / formula.
The –ignore-dependencies flag does just what it sounds like, it will ignore dependencies for the formula in question when uninstalling the designated package.
Managing Dependencies when Uninstalling Homebrew Packages
One thing to be mindful of when removing and uninstalling packages from Homebrew is that if the package being uninstalled has dependencies that are in use by another package or formula, then that may break it causing the secondary package to no longer work correctly. Perhaps the simplest way to prevent that is to use the optional –ignore-dependencies flag. For example:
brew uninstall --ignore-dependencies telnet
If you are not sure what dependencies exist with a particular Homebrew package, you can use the deps command to find that out:
brew deps packageName
For example, if you installed python3 on the Mac using the Homebrew approach, which has a fair amount of dependencies, running that command would look something like the following:
% brew deps python3 gdbm openssl readline sqlite xz
Since many other packages also use those dependencies, if you were to remove python3 you’d almost certainly want to issue the –ignore-dependencies flag. The same applies to node.js and npm, and many other popular Homebrew packages.
Do you know of any other methods or tips related to uninstalling Homebrew packages and formula? Share with us in the comments below!