DEV Community

James Murdza
James Murdza

Posted on

1

Ultimate Homebrew Cheatsheet 🍺

Below is my reference of useful commands for package management in Homebrew:

👀 Quick stats

Show Homebrew state:

brew info
Enter fullscreen mode Exit fullscreen mode

Show manually installed taps, kegs and packages in one list:

brew bundle dump --file=-
Enter fullscreen mode Exit fullscreen mode

📦 Manage packages and dependencies

See installed packages

List installed packages:

brew list # formulae and casks
brew list --formulae # just formulae
brew list --casks # just casks
Enter fullscreen mode Exit fullscreen mode

List installed packages which are not dependencies of any others:

brew leaves
brew leaves -r # installed manually
brew leaves -p # installed as dependencies
Enter fullscreen mode Exit fullscreen mode

List installed packages which are not dependencies of manually installed packages:

brew autoremove --dry-run
Enter fullscreen mode Exit fullscreen mode

See dependency tree

Show dependencies of the wget formula in a tree format:

brew deps --tree wget
Enter fullscreen mode Exit fullscreen mode

Show all installed formulae in a dependency tree format:

brew deps --tree --installed
brew deps --tree $(brew leaves) # remove duplicate showing of same dependency
Enter fullscreen mode Exit fullscreen mode

Show dependency tree for all casks:

brew deps --tree $(brew list --casks -1)
Enter fullscreen mode Exit fullscreen mode

Remove hanging dependencies

Uninstall hanging (no longer used) dependencies:

brew autoremove 
Enter fullscreen mode Exit fullscreen mode

Remove all packages

Remove all packages installed with Homebrew:

brew remove --force $(brew list) --ignore-dependencies
brew remove --force $(brew list --formulae) --ignore-dependencies # formulae only
brew remove --force $(brew list --casks) --ignore-dependencies # casks only
Enter fullscreen mode Exit fullscreen mode

🗄️ Manage files

Installation paths

Show key installation directories:

brew shellenv
brew --prefix
brew --repository
brew --cellar
brew --caskroom
Enter fullscreen mode Exit fullscreen mode

See installed files

Show files in the wget keg:

brew list wget # collapse directories
brew list wget --verbose # recurse directories
Enter fullscreen mode Exit fullscreen mode

Show symlinks to the wget keg:

unlink wget --dry-run
unlink wget --dry-run | xargs ls -l # show link destinations
Enter fullscreen mode Exit fullscreen mode

Show unneeded files:

brew cleanup --dry-run # old versions of packages
brew cleanup -s --dry-run # old versions of packages and cache files
Enter fullscreen mode Exit fullscreen mode

Remove unneeded files

Remove old versions of packages and cache files:

brew cleanup -s
Enter fullscreen mode Exit fullscreen mode

Completely erase the Homebrew cache folder:

rm -rf $(brew --cache)
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay