brew - macOS


Overview

Homebrew, commonly referred to as brew, is a free and open-source package management system specifically designed for macOS to simplify the installation of software. It simplifies the process of installing, updating, and managing software packages, making it an invaluable tool for developers and power users. Homebrew automates the installation process, reducing the complexity of command-line arguments and dependencies.

Syntax

brew command [options] [formula]
  • command refers to what you want brew to do (e.g., install, update).
  • options are modifiers that adjust the behavior of the command.
  • formula is the name of the software package you want to manage.

Options/Flags

  • -v, --verbose: Provides more detailed output on what brew is doing.
  • --version: Displays the version of the Homebrew installation.
  • install: Installs a new package.
    • --force: Install without checking for previously installed versions.
    • --ignore-dependencies: Skip installing any dependencies of the formula.
  • update: Updates Homebrew and all installed packages.
  • upgrade: Upgrades outdated installed packages.
  • uninstall, remove: Removes a package.
    • --force: Remove without confirmation.
  • list: Lists installed packages.
  • search: Searches for formulas in the Homebrew repository.

Examples

  1. Installing a Package:

    brew install wget
    

    This command installs the wget package.

  2. Updating Homebrew:

    brew update
    

    This refreshes your local list of available packages and their versions.

  3. Upgrading All Packages:

    brew upgrade
    

    This will upgrade all installed packages to their latest versions.

  4. Searching for a Package:

    brew search nginx
    

    Lists all packages related to nginx.

  5. Uninstalling a Package:

    brew uninstall --force nginx
    

    Forcefully removes the nginx package along with its configurations.

Common Issues

  • Permission Errors: Installation may fail due to insufficient permissions. Running sudo chown -R $(whoami) $(brew --prefix)/* can resolve permission issues.
  • Broken Dependencies: Sometimes an upgrade fails because of dependents. Use brew doctor to identify and fix these issues.
  • Slow Performance: If brew commands are slow, consider running brew cleanup to remove outdated versions and free up space.

Integration

Homebrew commands can be mixed with traditional Unix commands to create more powerful workflows:

brew list | grep 'python' | xargs brew uninstall

This command chain lists all brew-installed packages, filters for any that include ‘python’ and passes them to brew uninstall.

  • brew cask: Manages graphical applications in conjunction with the Homebrew package manager.
  • brew cleanup: Removes old versions of installed packages.
  • brew doctor: Checks your system for potential configuration issues.

For further reading on Homebrew, visit the official Homebrew documentation.