Build the toolchain

Understand the Homebrew prefix

Use Homebrew’s reported prefix instead of hard-coding an Intel or Apple silicon installation path.

Homebrew installs everything under one root directory, its prefix. The prefix is not the same everywhere. On Apple silicon it is /opt/homebrew. On Intel Macs it is /usr/local. Same tool, two layouts, and the difference is exactly the architecture split from the previous module.

Scripts that assume /usr/local or /opt/homebrew fail as soon as the environment changes. That could be a teammate on older hardware, a CI runner, or your own next Mac.

Ask Homebrew, don’t guess

Homebrew will tell you its own paths:

brew --prefix
# /opt/homebrew
brew --repository
# /opt/homebrew
brew --cellar
# /opt/homebrew/Cellar

The prefix is where binaries get linked (/opt/homebrew/bin). The repository is Homebrew’s own checkout. The Cellar is where each formula’s versioned files actually live.

When a script needs the location of something Homebrew installed, use command substitution:

export LDFLAGS="-L$(brew --prefix openssl@3)/lib"

brew --prefix openssl@3 resolves the real, current path of that formula on this machine. The same line works on Intel and Apple silicon.

Use command substitution only where a tool genuinely needs an absolute prefix, like linker flags. Prefer command -v when you only need the executable selected by the current PATH:

command -v node
# /opt/homebrew/bin/node

The two-prefix trap

On Apple silicon, /opt/homebrew/bin is not on the default PATH. The installer tells you to add this line to ~/.zprofile:

eval "$(/opt/homebrew/bin/brew shellenv)"

brew shellenv prints the exports for the correct prefix. eval applies them. Skip it and every brew-installed tool is invisible to new shells.

Here is the realistic failure. A Mac that once ran a translated x86_64 shell can end up with two Homebrew installations: an Intel one in /usr/local and a native one in /opt/homebrew. Both work, and PATH order silently decides which one serves each command. The tell is brew --prefix saying /usr/local on an arm64 Mac, or file $(command -v node) reporting x86_64. When you see that, pick the native install, migrate your formulas to it, and remove the Intel one deliberately.

Lesson completed