macOSHomebrew

Homebrew Guide: A Package Manager for Developers and Everyday Users

Homebrew is a powerful package manager for macOS and Linux that makes installing, updating, and removing software much simpler. This guide covers the basics, GUI apps with Cask, service management, common commands, and a few practical troubleshooting tips.

2024-11-21·11 min·计算中...

Homebrew is a powerful package manager for macOS and Linux. It makes installing, updating, and removing software much simpler. If you are a developer, or just want to manage tools more efficiently, this guide will help you get started quickly.


1. What is Homebrew?

Homebrew is a package manager built around one core idea: make missing things simple. Through a command-line interface, it helps you install, manage, update, and remove software packages and tools with very little friction. Whether you are setting up a development environment or just managing useful apps, Homebrew makes the process cleaner.


2. Installing Homebrew

2.1 Requirements

  • macOS: macOS 10.14 or newer
  • Linux: major distributions are supported; install basic development tools such as gcc and curl first

2.2 Installation steps

  1. Open Terminal.
  2. Run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Follow the prompts and enter your password when needed.
  2. Configure environment variables if required. In many cases this is done automatically.

Verify the installation:

brew --version

If you see a version number, Homebrew is installed correctly.


3. Basic commands

Command What it does
brew install <package> install a package
brew uninstall <package> uninstall a package
brew search <keyword> search for packages
brew list list installed packages
brew info <package> show package details
brew update update Homebrew itself
brew upgrade upgrade installed packages
brew cleanup remove old versions and cache files
brew doctor diagnose common Homebrew issues

4. Installing and managing packages

4.1 Install a package

brew install wget

In this example, Homebrew installs wget, along with any dependencies it needs.

4.2 View package information

brew info wget

This shows the package version, installation path, and dependency details.

4.3 Uninstall a package

brew uninstall wget

This removes the package and cleans up its associated files.


5. Managing GUI apps with Homebrew Cask

Homebrew is not only for developer tools and command-line utilities. Through Homebrew Cask, it can also manage macOS GUI apps such as Google Chrome, Visual Studio Code, and Spotify. It makes installing and removing desktop apps as simple as a command.


5.1 What is Homebrew Cask?

Homebrew Cask is a Homebrew extension used to install and manage GUI apps on macOS. It installs apps directly into /Applications, so you use them just like normally installed apps.

Typical examples include:

  • Browsers: Google Chrome, Firefox
  • Developer tools: Visual Studio Code, Postman
  • Media apps: VLC, Spotify

5.2 Install GUI apps

Use the following command:

brew install --cask <app-name>

Example:

brew install --cask google-chrome

5.3 Search for GUI apps

brew search --cask <keyword>

Example:

brew search --cask chrome

5.4 Uninstall GUI apps

brew uninstall --cask <app-name>

Example:

brew uninstall --cask google-chrome

5.5 Why Homebrew Cask is useful

  1. Apps go directly into /Applications

    • They behave just like apps installed through the usual drag-and-drop workflow.
  2. It is faster

    • You do not need to visit websites and download DMG files manually.
  3. Dependency management

    • If an app requires supporting libraries or tools, Homebrew handles them.
  4. Unified upgrades

    • brew upgrade updates both command-line tools and GUI apps installed through Homebrew.

Category Apps
Browsers google-chrome, firefox
Developer tools visual-studio-code, postman, iterm2
Media tools vlc, spotify
Communication slack, zoom
Utilities alfred, rectangle

Example installs:

brew install --cask vlc
brew install --cask visual-studio-code
brew install --cask rectangle

5.7 Listing and updating Cask apps

List installed GUI apps:

brew list --cask

Update everything installed through Homebrew and Cask:

brew update && brew upgrade

Clean old versions and cached files:

brew cleanup

View detailed information about a Cask app:

brew info --cask google-chrome

That shows the install path, version, and whether auto-update is supported.


6. Common Homebrew Cask questions

6.1 Can I install older GUI app versions?

Homebrew Cask does not directly support old GUI versions in the normal flow. If you need one, you usually have to locate an older cask definition manually.

6.2 What if a Cask app fails to install?

Possible causes include network issues or upstream changes.

  • Try updating Homebrew:
brew update
  • Then inspect the error output and follow the relevant fix.

6.3 Where can I browse all supported GUI apps?

See the official Homebrew Cask catalog:
https://formulae.brew.sh/cask/


7. Service management with Homebrew Services

With brew services, you can start, stop, and restart background services such as databases and web servers.

Start a service:

brew services start mysql

Stop a service:

brew services stop mysql

List service status:

brew services list

8. Common issues and fixes

8.1 Permission issues

If you run into permission errors during installation, you may need to change the ownership of the install directory:

sudo chown -R $(whoami):admin /usr/local

8.2 Disk cleanup

Over time, Homebrew accumulates old cache files. Free space with:

brew cleanup

8.3 Installing a specific version

Some packages support versioned formulas:

brew install <package>@<version>

Example:

brew install python@3.9

9. Advanced tips

9.1 Custom install prefix

Homebrew usually installs into /usr/local or /opt/homebrew. If you need a custom location, you can work with the HOMEBREW_PREFIX environment variable.

9.2 Add custom taps

If the official repositories do not include the software you need, add a community tap:

brew tap <repo-name/repo-url>

10. Typical use cases

  • Developers: set up Node.js, Python, Git, Docker, and other tooling
  • Everyday users: quickly install apps such as VLC or Chrome
  • System administrators: manage services such as MySQL and Redis

11. Final thoughts

Homebrew makes software management on macOS and Linux much easier, especially if you care about speed and consistency. If you have never used it before, it is absolutely worth trying.

References:

If this guide helped, keep exploring. Homebrew becomes more valuable the more of your setup you standardize around it.

Subscribe to FreeMac

Weekly picks: Mac productivity tips, free alternatives to paid software, and developer tools. Master your MacBook and save money.

← Back to articles