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 zerobrewhq / zerobrew

An up to 5x faster Homebrew client

zerobrew

English · 中文

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

The installer updates your shell config. After it finishes, restart your terminal or run the source command it prints.

Or via Homebrew:

brew install zerobrewhq/zerobrew/zerobrew
Enter fullscreen mode Exit fullscreen mode

Update zerobrew

If you used the standalone installer, rerun it:

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

If you installed with Homebrew:

brew update && brew upgrade zerobrew
Enter fullscreen mode Exit fullscreen mode

If you installed from the old lucasgelfond/zerobrew tap, it's no longer updated. Switch to the new one:

brew uninstall zerobrew
brew untap lucasgelfond/zerobrew
brew install zerobrewhq/zerobrew/zerobrew
Enter fullscreen mode Exit fullscreen mode

Quick start

To opt in to a brew compatibility entrypoint:

zb install-alias brew
brew install jq
zb install-alias brew --remove
Enter fullscreen mode Exit fullscreen mode

This creates brew -> zb-brew beside zb; ensure that directory is on PATH. You can also enable it during installation:

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

Enabling…

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)