Skip to content

Instantly share code, notes, and snippets.

@uchilaka
Last active December 8, 2021 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uchilaka/8450991f90547514408d7b5c394efb23 to your computer and use it in GitHub Desktop.
Save uchilaka/8450991f90547514408d7b5c394efb23 to your computer and use it in GitHub Desktop.
Notes on Uninstalling Homebrew

Notes on Uninstalling Homebrew

from macOS Monterey on M1

You might get this console message when uninstalling homebrew

~ sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Password:
Warning: This script will remove:
/Users/localadmin/Library/Caches/Homebrew/
/Users/localadmin/Library/Logs/Homebrew/
/opt/homebrew/.dockerignore
/opt/homebrew/.editorconfig
/opt/homebrew/.git/
/opt/homebrew/.github/
/opt/homebrew/.gitignore
/opt/homebrew/.shellcheckrc
/opt/homebrew/.sublime/
/opt/homebrew/.vale.ini
/opt/homebrew/.vscode/
/opt/homebrew/CHANGELOG.md
/opt/homebrew/CONTRIBUTING.md
/opt/homebrew/Caskroom/
/opt/homebrew/Cellar/
/opt/homebrew/Dockerfile
/opt/homebrew/LICENSE.txt
/opt/homebrew/Library//
/opt/homebrew/README.md
/opt/homebrew/bin/brew
/opt/homebrew/completions/
/opt/homebrew/docs/
/opt/homebrew/manpages/
Are you sure you want to uninstall Homebrew? This will remove your installed packages! [y/N] y
==> Removing Homebrew installation...
==> Removing empty directories...
==> /usr/bin/sudo /usr/bin/find /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/opt /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/Frameworks -name .DS_Store -delete
==> /usr/bin/sudo /usr/bin/find /opt/homebrew/bin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/opt /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/Frameworks -depth -type d -empty -exec rmdir {} ;
==> Homebrew uninstalled!
The following possible Homebrew files were not deleted: # <-- Interesting section starts here. WTF uninstaller?!
/opt/homebrew/Frameworks/
/opt/homebrew/SECURITY.md
/opt/homebrew/bin/
/opt/homebrew/etc/
/opt/homebrew/include/
/opt/homebrew/lib/
/opt/homebrew/opt/
/opt/homebrew/sbin/
/opt/homebrew/share/
/opt/homebrew/var/
You may wish to remove them yourself.

The interesting bits here are the list of directories that the brew uninstaller did NOT take out for you. There are several reasons why this might make sense - one that comes to mind for me is a lot of the stuff downloaded to these directories are pretty chunky utilities, so should you turn around and do a re-install, you'll have an easier time getting up to speed if your issue wasn't "universal" like mine was (in my case, I was running in compatibility mode (via Rosetta), but also needed to do stuff that expected homebrew to be installed in a different path than the default for arm64).

Should you still want to clean these out, here's a shell script you can run:

# /some/where/clean-homebrew.sh
HOMEBREW_PREFIX="/opt/homebrew"
if ! [ -d "$HOMEBREW_PREFIX" ]; then 
  HOMEBREW_PREFIX="/usr/local/homebrew"
fi

cat << EOF
Working with Homebrew prefix: ${HOMEBREW_PREFIX}

EOF

stragglers=(Frameworks SECURITY.md bin etc include lib opt sbin share var)

force_clean() {
  for xpath in ${stragglers[@]}; do
    TARGET_ABS_PATH="$HOMEBREW_PREFIX/$xpath"
    if [ -f "$TARGET_ABS_PATH" ]; then
      echo "Target ${TARGET_ABS_PATH} is a file! Removing..."
      rm -v $TARGET_ABS_PATH
    else
      if [ -d "$TARGET_ABS_PATH" ]; then
        echo "Target ${TARGET_ABS_PATH} is a directory! Removing..."
        rm -Rvf $TARGET_ABS_PATH
      else
        echo "Target ${TARGET_ABS_PATH} not found"
      fi
    fi
  done
}

force_clean

Acknowledgements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment