[Homebrew (brew) Cheatsheet] Homebrew (brew) Basics Commands

Homebrew - The Missing Package Manager for macOS (or Linux)

Homebrew is an essential piece of software to help you organize the tools you use. The package manager allows you to install a large number of software like NodeJS or new versions of Git and will help you to keep them up to date.

These Homebrew commands will help you installing and maintaining the set of tools you need to develop good software.

Installation

1
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Commands

brew install

Homebrew will give you a convenient way to install a package as simple as running the following in your terminal:

1
brew install <package>

brew upgrade, update outdated

You want to update a specific package? Run the following command:

1
2
3
4
$ brew upgrade <package>

# Update all installed packages.
$ brew upgrade

If there is a package that you want to exclude from further updates, you can pin the package’s version like this:

1
2
3
4
$ brew pin <package>

# Undone by running
$ brew unpin <package>

In order to update Homebrew itself, run brew update.

1
$ brew update

Simply run the following command to check all packages at once:

1
$ brew outdated

brew cask

Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Tap the Cask repository from Github.
$ brew tap homebrew/cask

# List all the installed casks .
$ brew cask list

# Search all known casks based on the substring text.
$ brew search <text>

# Install the given cask.
$ brew cask install <cask>

# Reinstalls the given Cask
$ brew cask reinstall <cask>

# Uninstall the given cask.
$ brew cask uninstall <cask>

brew search, info

To check if there is a specific package, you can run:

1
$ brew search <term>

Homebrew will list all matching packages that you can install with brew install <package> as mentioned above.

Before installing a package, you can also lookup some information about it by running:

1
$ brew info <package>

This will give you a description and further dependencies and requirements.

brew service

1
2
3
4
5
$ brew services list

$ brew services start <service>

$ brew services stop <service>

brew cleanup

Clean up old versions of all packages.

1
$ brew cleanup

Clean up the old version of the specified package.

1
$ brew cleanup <package>

Remove old symlinks.

1
$ brew prune

Uninstall everything.

1
$ brew remove --force --ignore-dependencies $(brew list)

brew uninstall

To remove our package, we can run the uninstall task:

1
$ brew uninstall <package>

View the old version package that can be cleaned up without performing actual operations.

1
$ brew cleanup -n

brew tab

It is possible to add additional repositories to homebrew by making use of the brew tap command. This allows you to install additional applications that does not form part of the default set of repositories.

1
2
3
4
5
6
7
8
9
10
11
# List all the current tapped repositories (taps)
$ brew tap

# Tap a formula repository from Github using https for tap https://github.com/user/homebrew-repo
$ brew tap <user/repo>

# Tap a formula repository from the specified URL
$ brew tap <user/repo> <URL>

# Remove the given tap from the repository
$ brew untap <user/repo>

brew analytics

If you don’t mind the collection of metrics then you do not have to do anything. If you do not want to be anonymously tracked then simply turn off the analytics:

1
2
3
4
5
6
7
$ brew analytics
Analytics are enabled.

$ brew analytics off

$ brew analytics
Analytics are disabled.

brew doctor

Try brew doctor first! It will give you a bunch of useful hints like:

1
$ brew doctor

Uninstall Homebrew

1
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

References

[1] The Missing Package Manager for macOS (or Linux) — Homebrew - https://brew.sh/

[2] FAQ — Homebrew Documentation - https://docs.brew.sh/FAQ

[3] Homebrew - Basics Commands and Cheatsheet - DEV Community - https://dev.to/code2bits/homebrew—basics–cheatsheet-3a3n

[4] 5 Essential Homebrew Commands You Should Know | by Steven | Steven’s Blog - https://blog.steven266.de/5-essential-homebrew-commands-you-should-know-ab6ecee0f7ee