Package Manager – Homebrew
A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer's operating system in a consistent manner. Package managers typically maintain a database of software dependencies and version information to prevent software mismatches and missing prerequisites.
Homebrew is the most widely used package manager for macOS and Linux. It is free, open-source, and covers almost every development tool that we need — pyenv, git, openssl, and more — each installable and upgradeable with a single command.
Checking for an Existing Installation
Let's check whether Brew is already installed or not:
% which brew
brew not found
Installing Homebrew
Homebrew installation needs CLT (which we installed in previous chapter) and a Unix shell (either bash or zsh — both present on macOS by default). The zsh — built on top of bash (the default shell for older macOS) with additional features — is recommended shell over bash itself. New macOS (Catalina 10.15 and later versions) already has zsh installed and set as default. If not, we can still proceed to install brew (as it needs bash only) and then can set zsh as default shell later. In both cases (bash or zsh), let's start with brew installation:
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
==> Checking for `sudo` access (which may request your password).
Password:
==> This script will install:
...
Press RETURN to continue or any other key to abort
...
==> Downloading and installing Homebrew...
...
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
The script shows the directories it will create and asks you to press Return to proceed. On Apple Silicon Macs, Homebrew installs to /opt/homebrew rather than /usr/local.
In case, the default shell was still bash and not zsh, we can switch it with following commands:
% brew install zsh
% chsh -s $(which zsh)
After running these two commands, closing and re-opening the terminal, it opens with Z Shell (zsh).
PATH Configuration (Apple Silicon)
On Apple Silicon, the installer may warn that /opt/homebrew/bin is not in your PATH. If which brew still returns "brew not found" after installation, we need to run:
% echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
% eval "$(/opt/homebrew/bin/brew shellenv)"
% which brew
/opt/homebrew/bin/brew
Note: On Intel Macs, brew installs to /usr/local/bin/brew and this step is unnecessary.
