DEV Community

Cover image for 6 Must-know commands for cleaning up Homebrew packages
0xkoji
0xkoji

Posted on

6 Must-know commands for cleaning up Homebrew packages

I recently discovered "zerobrew" and decided to switch over from Homebrew. To prepare for the transition, I've been cleaning up my Homebrew packages using these commands.

Since zerobrew doesn't support every package available on Homebrew yet (for example, "Codex"), I'm currently running both side-by-side.

zb install codex
==> Installing codex...

Note: This package can't be installed with zerobrew.
      Error: missing formula 'codex'

      Try installing with Homebrew instead:
      brew install codex

error: missing formula 'codex'
Execution time: 0.94s
Enter fullscreen mode Exit fullscreen mode

GitHub logo lucasgelfond / zerobrew

A 5-20x faster experimental Homebrew alternative

zerobrew

Lint Test Release Discord License: MIT License: Apache 2.0

zerobrew demo

zerobrew brings uv-style architecture to Homebrew packages on macOS and Linux.

Install

curl -fsSL https://zerobrew.rs/install | bash
Enter fullscreen mode Exit fullscreen mode

After install, run the export command it prints (or restart your terminal).

Quick start

zb install jq                   # install one package
zb install wget git             # install multiple
zb bundle                       # install from Brewfile
zb bundle install -f myfile     # install from custom file
zb bundle dump                  # export installed packages to Brewfile
zb bundle dump -f out --force   # dump to custom file (overwrite)
zb uninstall jq                 # uninstall one package
zb reset                        # uninstall everything
zb gc                           # garbage collect unused store entries
zbx jq --version                # run without linking
Enter fullscreen mode Exit fullscreen mode

Performance snapshot

Package Homebrew ZB (cold) ZB (warm) Cold Speedup Warm Speedup
Overall (top 100) 452s 226s 59s 2.0x 7.6x
ffmpeg 3034ms 3481ms 688ms 0.9x 4.4x
libsodium 2353ms 392ms 130ms 6.0x 18.1x
sqlite 2876ms 625ms 159ms 4.6x 18.1x
tesseract 18950ms
…

brew leaves

Show packages that are not dependencies of other packages.

brew autoremove

Remove unused dependencies that are no longer needed.

brew doctor

To diagnose and fix potential issues in my setup.

brew cleanup

Remove stale lock files and outdated downloads.

Usage: brew cleanup [options] [formula|cask ...]

Remove stale lock files and outdated downloads for all formulae and casks, and
remove old versions of installed formulae. If arguments are specified, only do
this for the given formulae and casks. Removes all downloads more than 120 days
old. This can be adjusted with $HOMEBREW_CLEANUP_MAX_AGE_DAYS.

      --prune                      Remove all cache files older than specified
                                   days. If you want to remove everything, use
                                   --prune=all.
  -n, --dry-run                    Show what would be removed, but do not
                                   actually remove anything.
  -s, --scrub                      Scrub the cache, including downloads for even
                                   the latest versions. Note that downloads for
                                   any installed formulae or casks will still
                                   not be deleted. If you want to delete those
                                   too: rm -rf "$(brew --cache)"
      --prune-prefix               Only prune the symlinks and directories from
                                   the prefix and remove no other files.
  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -v, --verbose                    Make some output more verbose.
  -h, --help                       Show this message.
Enter fullscreen mode Exit fullscreen mode

brew bundle dump

Create a Brewfile to snapshot your current setup.

brew bundle --force cleanup

Uninstall everything not listed in your Brewfile.

I have used the alias, brew_all

.zshrc

alias brew_all="brew outdated && brew update && brew upgrade && brew cleanup -s"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)