How to Completely Uninstall Homebrew and Remove All Its Files

Updated: January 28, 2024 By: Guest Contributor Post a comment

Introduction

Homebrew is a popular package manager for macOS, allowing developers to install applications, tools, and utilities easily. However, there might come a time when you need to remove Homebrew and all associated files from your system completely. This tutorial will guide you through the process, step by step.

Basic Uninstallation of Homebrew

Uninstalling Homebrew is relatively straightforward, as the package manager includes a script designed to uninstall itself. To begin, open a terminal window and input the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

This will execute the uninstall script that is hosted on Homebrew’s official GitHub repository. The terminal will output a series of operations as it removes Homebrew from your system. It should look something like this:

==> Removing Homebrew installation...
==> Uninstalling /usr/local/Homebrew...
==> Removing Homebrew-related cache files...

Verifying Homebrew Uninstallation

After running the uninstallation script, it’s a good idea to check if Homebrew has been completely removed. You can do this by running:

brew --version

If you see a message saying ‘command not found: brew’, then Homebrew has been removed. However, if you still see a Homebrew version output, some part of Homebrew may remain on your system.

Removing Additional Homebrew Files

In some cases, the uninstall script may not remove all Homebrew-related files. To manually remove any remaining files, you can delete the Homebrew directory:

sudo rm -rf /usr/local/Homebrew

Additionally, Homebrew stores cache files that may remain. These can be found and removed with:

rm -rf $(brew --cache)

Cleaning Up Your System

After uninstalling Homebrew, it’s important to clean up any remaining files that were linked by Homebrew. You will need to unlink these files:

brew list -1 | xargs -L1 brew unlink

You can also remove all the directories and files that were linked with Homebrew:

sudo rm -rf /usr/local/bin /usr/local/sbin /usr/local/etc /usr/local/share

Keep in mind that this action may remove files not related to Homebrew, so proceed with caution and ensure that these directories don’t contain non-Homebrew files you need.

Advanced Cleanup

If you’ve used Homebrew for a significant period, you might have brew services or scheduled jobs. To remove these, first list and then stop all running services:

brew services list
brew services stop --all

You’ll also want to check your profile files for any additional Homebrew paths. Common profile files include ~/.bash_profile, ~/.zshrc, and ~/.profile. You may locate and edit these by using a text editor, such as nano:

nano ~/.bash_profile

Look for lines that add /usr/local/bin to your PATH and remove them. Don’t forget to also look for any Homebrew-related environment variables, such as HOMEBREW_NO_AUTO_UPDATE, and remove those too. You can use PATHEXPORT or GREP to trace these entries:

grep 'Homebrew' ~/.bash_profile

Final Check

To ensure that Homebrew and its files are completely uninstalled, you can use the Finder or the find command in terminal:

find / -name '*brew*' -print

This command will list all items related to Homebrew. If you spot any files that shouldn’t be there, you can remove them using the rm command. Do this with extreme caution, as removing system files can affect your macOS installation.

Conclusion

In this tutorial, we’ve covered how to completely uninstall Homebrew and remove all associated files. Following these steps ensures a clean slate, allowing you to either reinstall Homebrew cleanly or pass on your system free of unnecessary files.