# Homebrew — The brew Package Manager for macOS and Linux

> Practical guide to Homebrew (brew) — install, update, and manage formulae and casks, plus services and Brewfile setups on macOS and Linux.

Source: https://www.jpkc.com/db/en/cheatsheets/package-managers/brew/

<!-- PROSE:intro -->
Homebrew is "the missing package manager" for macOS – and it has long run on Linux too. With the `brew` command you install, update, and remove command-line tools without worrying about compiler flags or system paths. Homebrew distinguishes two worlds: **formulae** are classic CLI packages, while **casks** deliver ready-made GUI applications to the Mac. This guide walks you through the commands you actually reach for day to day – from installing through updates and dependencies to services and reproducible setups via a Brewfile.
<!-- PROSE:intro:end -->

## Install & Search

`brew install <formula>` — Install a command-line package (formula).

```bash
brew install wget
```

`brew install --cask <cask>` — Install a GUI application (cask, macOS only).

```bash
brew install --cask firefox
```

`brew search <query>` — Search for packages by name.

```bash
brew search node
```

`brew info <formula>` — Show detailed info about a package.

```bash
brew info nginx
```

`brew home <formula>` — Open the homepage of a package in a browser.

```bash
brew home git
```

## Update & Upgrade

`brew update` — Update Homebrew and all tap repositories.

```bash
brew update
```

`brew upgrade` — Upgrade all installed packages to latest versions.

```bash
brew upgrade
```

`brew upgrade <formula>` — Upgrade a specific package.

```bash
brew upgrade node
```

`brew outdated` — List installed packages with available updates.

```bash
brew outdated
```

`brew pin <formula>` — Pin a package to prevent upgrading.

```bash
brew pin postgresql@15
```

`brew unpin <formula>` — Unpin a package to allow upgrading.

```bash
brew unpin postgresql@15
```

## Uninstall & Cleanup

`brew uninstall <formula>` — Uninstall a package.

```bash
brew uninstall wget
```

`brew uninstall --cask <cask>` — Uninstall a cask application.

```bash
brew uninstall --cask firefox
```

`brew cleanup` — Remove old versions and clear download cache.

```bash
brew cleanup
```

`brew cleanup -s` — Scrub the cache including latest versions.

```bash
brew cleanup -s
```

`brew autoremove` — Remove unused dependencies (orphans).

```bash
brew autoremove
```

## List & Dependencies

`brew list` — List all installed formulae.

```bash
brew list
```

`brew list --cask` — List all installed casks.

```bash
brew list --cask
```

`brew deps <formula>` — Show dependencies of a package.

```bash
brew deps nginx
```

`brew deps --tree <formula>` — Show dependency tree.

```bash
brew deps --tree php
```

`brew uses --installed <formula>` — Show which installed packages depend on a formula.

```bash
brew uses --installed openssl
```

`brew leaves` — List packages that are not dependencies of other packages.

```bash
brew leaves
```

## Services

`brew services list` — List all managed services and their status.

```bash
brew services list
```

`brew services start <formula>` — Start a service (and register for login).

```bash
brew services start postgresql@15
```

`brew services stop <formula>` — Stop a service (and deregister).

```bash
brew services stop postgresql@15
```

`brew services restart <formula>` — Restart a service.

```bash
brew services restart nginx
```

`brew services run <formula>` — Start a service without registering for login.

```bash
brew services run redis
```

## Taps & Diagnostics

`brew tap` — List all installed taps (third-party repositories).

```bash
brew tap
```

`brew tap <user>/<repo>` — Add a third-party tap.

```bash
brew tap homebrew/cask-fonts
```

`brew untap <user>/<repo>` — Remove a tap.

```bash
brew untap homebrew/cask-fonts
```

`brew doctor` — Check for potential problems with the installation.

```bash
brew doctor
```

`brew config` — Show Homebrew and system configuration.

```bash
brew config
```

`brew bundle dump` — Generate a Brewfile from currently installed packages.

```bash
brew bundle dump --file=~/Brewfile
```

`brew bundle install` — Install all packages from a Brewfile.

```bash
brew bundle install --file=~/Brewfile
```

<!-- PROSE:outro -->
## Conclusion

Homebrew takes the tedious manual work out of installing software and keeps your system current with a quick `brew update && brew upgrade`. Never run `brew` with sudo – Homebrew deliberately works inside its own directory, and `sudo` will break its permissions. Commands like `brew cleanup` and `brew uninstall` delete files irreversibly, and casks download executable binaries from the internet – so only install what you recognize from a trusted source. For reproducible setups, a version-controlled Brewfile pays off: generate it once with `brew bundle dump`, then recreate the exact same environment on any new machine with `brew bundle install`.

## Further Reading

- [brew.sh](https://brew.sh/) – official project site with installation instructions
- [docs.brew.sh](https://docs.brew.sh/) – detailed documentation and reference
- [Homebrew – GitHub project](https://github.com/Homebrew/brew) – source code, releases and issues
<!-- PROSE:outro:end -->

## Related Commands

- [apk](https://www.jpkc.com/db/en/cheatsheets/package-managers/apk/) – Alpine Linux package manager, lean and fast
- [apt](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt/) – modern package management for Debian and Ubuntu
- [apt-get](https://www.jpkc.com/db/en/cheatsheets/package-managers/apt-get/) – classic APT tool for scripts and automation

