How to completely uninstall Homebrew without leftover files in macOS ?
To completely uninstall Homebrew from your macOS system without leaving any leftover files, you need to follow a two-step process:
First, uninstall Homebrew and its packages.
Second, manually locate and remove any remaining files.
Below are the detailed steps described in this video:–
SO, How to uninstall Homebrew package and remove any leftover files?
Step 1: Uninstall Homebrew and Its Packages
1- Open Terminal:
- Go to
Applications > Utilities > Terminal
, or use Spotlight (Command + Space
, type “Terminal”).
2- List Installed Packages (Optional):
- To see what Homebrew has installed, run:
brew list
- This helps you confirm what’s present before uninstalling.
3- Uninstall All Homebrew Packages:
- Remove all installed packages (formulae and casks) with:
brew uninstall --force $(brew list --formula) brew uninstall --force $(brew list --cask)
--force
ensures no prompts interrupt the process.
4- Run the Official Uninstall Script:
- Homebrew provides a script to remove itself. Download and execute it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
- Follow the prompts:
- Type
y
and pressEnter
to confirm uninstallation. - If it asks for your admin password, enter it.
- Type
- This removes Homebrew’s core files (e.g.,
/usr/local/Homebrew
or/opt/homebrew
on Apple Silicon).
5- Verify Homebrew is Gone:
- Run:
brew --version
- If it returns “command not found,” Homebrew is uninstalled.
Step 2: Find and Remove Leftover Files
Homebrew’s uninstall script removes its main components, but some residual files (e.g., caches, configuration files, or manually installed dependencies) may remain. Here’s how to clean them up:
1- Check Common Homebrew Directories:
- Open Terminal and inspect these locations:
- Intel Macs:
/usr/local/Cellar
,/usr/local/Homebrew
,/usr/local/bin/brew
- Apple Silicon Macs:
/opt/homebrew/Cellar
,/opt/homebrew/Homebrew
,/opt/homebrew/bin/brew
- Intel Macs:
- Remove them manually:
sudo rm -rf /usr/local/Cellar /usr/local/Homebrew /usr/local/bin/brew
- Or for Apple Silicon:
sudo rm -rf /opt/homebrew/Cellar /opt/homebrew/Homebrew /opt/homebrew/bin/brew
- Or for Apple Silicon:
- Enter your admin password when prompted.
2- Remove Homebrew Cache:
- Delete the cache folder:
rm -rf ~/Library/Caches/Homebrew
3- Remove Configuration Files:
- Check for Homebrew-related config files:
rm -rf ~/.brew rm -f ~/.zshrc.brew # If you added Homebrew to your shell
- If you use Bash or Zsh, check
~/.zshrc
or~/.bash_profile
for Homebrew PATH entries (e.g.,eval "$(/opt/homebrew/bin/brew shellenv)"
) and remove them with a text editor:nano ~/.zshrc
- Delete the line, save (
Control + X
, thenY
, thenEnter
), and reload the shell:source ~/.zshrc
- Delete the line, save (
4- Remove Lingering Binaries or Links:
- Check
/usr/local/bin
or/opt/homebrew/bin
for symlinks:ls -l /usr/local/bin | grep brew
- Delete any Homebrew-related links:
sudo rm -f /usr/local/bin/brew /usr/local/bin/<package-name>
5- Search for Stray Files:
- Use
find
to locate any remaining Homebrew files:sudo find / -name "*homebrew*" -exec rm -rf {} + 2>/dev/null sudo find / -name "*brew*" -exec rm -rf {} + 2>/dev/null
- This searches your entire system and deletes matches (errors are suppressed with
2>/dev/null
).
6- Empty the Trash:
- In Finder, right-click the Trash >
Empty Trash
(orCommand + Shift + Delete
and confirm) to remove all deleted files permanently.
7- Verify Cleanup:
- Restart Terminal and check:
which brew
- If it returns nothing or “not found,” Homebrew is fully gone.
- Check storage: Apple menu >
About This Mac
>Storage
to confirm space is freed.
Notes
- Architecture Matters:
- Intel Macs use
/usr/local
, while Apple Silicon uses/opt/homebrew
. Adjust paths based on your Mac (rununame -m
in Terminal:x86_64
= Intel,arm64
= Apple Silicon). - Caution:
- Be careful with
sudo rm -rf
—only delete files you’re sure are Homebrew-related to avoid removing system files.