brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: brew shellenv in ~/.zprofile puts Homebrew on your PATH

Terminal
~/tips/tip-macos-brew-shellenv-zprofile

echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >> ~/.zprofile

Makes Homebrew commands and man pages work in every new zsh login shell.

On an Apple silicon Mac like my MacBook Pro, Homebrew installs into /opt/homebrew, and your shell has to be told about that folder. The clean way is one line in your zsh login file, and it’s worth getting right on a fresh Mac.

This adds it:

echo 'eval "$(/opt/homebrew/bin/brew shellenv zsh)"' >> ~/.zprofile

brew shellenv prints export statements. When the shell runs them, Homebrew lands in your PATH, MANPATH and INFOPATH, and you also get HOMEBREW_PREFIX, HOMEBREW_CELLAR and HOMEBREW_REPOSITORY so tools do not have to ask Homebrew for them over and over. The manual suggests ~/.zprofile on macOS, and Apple explains why that file: .zprofile runs at login, including over SSH, while .zshrc runs for each new Terminal session.

Open a new Terminal tab and check it:

brew --prefix

That should print /opt/homebrew. Running the line twice does no harm either: the command prints nothing when Homebrew’s bin and sbin are already first and second in your PATH.

One caveat: name the shell. Without the zsh argument, brew shellenv tries to detect your shell, and the manual warns that this may not be correct. If you use bash, write bash there and put the line in ~/.bash_profile instead.

Further reading: Homebrew manpage, Homebrew installation, Apple Support: Use zsh as the default shell on Mac

Going deeper: Guide: keep your Mac apps in a Brewfile, so a new MacBook is one command away

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link