How to use the command `brew install` (with examples)
The brew install
command is used to install a Homebrew formula or cask. Homebrew is a package manager for macOS that allows you to easily install, uninstall, and manage software packages on your system. With the brew install
command, you can install software packages from the Homebrew repositories.
Use case 1: Install a formula/cask
Code:
brew install formula|cask
Motivation:
The motivation for using this example is to install a specific software package or application on your macOS system. The formula parameter represents a specific formula (package) from the Homebrew repositories, while the cask parameter represents a specific cask (application) from the Homebrew Cask repositories.
Explanation:
brew install
: This is the main command used to install software packages using Homebrew.formula|cask
: This is a placeholder indicating that you need to replace it with the actual name of the formula or cask you want to install. For example, to install the Python programming language, you would usebrew install python
.
Example output:
==> Downloading formula: python
==> Downloading https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz (23.6 MB)
==> Pouring python-3.10.0.tar.xz
==> Caveats
Python has been installed as
...
==> Summary
🍺 /usr/local/Cellar/python/3.10.0_1: 4,004 files, 62.0MB
Use case 2: Build and install a formula from source
Code:
brew install --build-from-source formula
Motivation:
The motivation for using this example is to build and install a software package from the source code, instead of using pre-built binaries. This can be useful if you want to customize the build options or contribute to the development of the software.
Explanation:
--build-from-source
: This argument tells Homebrew to build the formula from source instead of using pre-built binaries.formula
: This is the name of the formula you want to build and install from source.
Example output:
==> Cloning https://github.com/Homebrew/homebrew-core.git
Updating /usr/local/Homebrew...
...
==> Downloading example_formula
==> Downloading https://github.com/example/example_formula/archive/v1.0.0.tar.gz
==> Downloading from https://github-production-release-asset-...
==> Compiling example_formula
==> Installing example_formula
...
Use case 3: Download the manifest, print what would be installed but don’t actually install anything
Code:
brew install --dry-run formula|cask
Motivation:
The motivation for using this example is to preview the installation process without actually making any changes to your system. This can be helpful if you want to know the dependencies and files that would be installed before proceeding with the actual installation.
Explanation:
--dry-run
: This argument tells Homebrew to simulate the installation process without actually installing anything.formula|cask
: This is the placeholder indicating that you need to replace it with the actual name of the formula or cask you want to simulate the installation for.
Example output:
==> Downloading formula: example_formula
==> Downloading https://github.com/example/example_formula/archive/v1.0.0.tar.gz
==> Downloading from https://github-production-release-asset-...
This is a dry run, the following files would have been installed:
...
Conclusion:
The brew install
command is a powerful tool for installing software packages and applications on macOS using Homebrew. It provides various options and arguments to customize the installation process, such as installing from source, simulating the installation, and installing specific formulas or casks. By familiarizing yourself with these use cases, you can efficiently manage and maintain software packages on your macOS system.