Homebrew

Setup Homebrew using a dedicated, non-privileged macOS user

In all of the following, one thing is taken as a given: using the recommended default prefix as the Homebrew install location. This will be /opt/homebrew on ARM, and /usr/local on Intel.

Setup

This extends Homebrew's alternative installation method of untarring anywhere to never needing to give brew, or the default install script, admin privileges to your Mac.

The steps are:

Prepare

In System Preferences, create a standard macOS user named homebrew.

Yet to be found out: can you somehow hide this user in the macOS login window?

ARM

As your sudo-capable macOS admin user:

sudo mkdir /opt/homebrew
cd /opt/homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | sudo tar xz --strip 1
sudo chown -R homebrew:admin /opt/homebrew

Finish up as the homebrew user:

su - homebrew
echo "cd /opt/homebrew" >> ~/.zshrc
brew update

Intel

As your sudo-capable macOS admin user:

cd /usr/local && curl -L https://github.com/Homebrew/brew/tarball/master | sudo tar xz --strip 1
sudo chown -R homebrew:admin /usr/local

Opening a new Terminal tab:

su - homebrew
echo "cd /usr/local" >> ~/.zshrc
brew update

GUI applications

Aside from your standard Unix command line tools, GUI applications installed via Homebrew need a bit of extra fondling.

Firstly, you will want to avoid, when installing a GUI tool, this prompt:

==> Creating Caskroom directory: /usr/local/Caskroom
We'll set permissions properly so we won't need sudo in the future.
Password:

…because the password prompt is for running sudo, which by definition your non-privileged homebrew user account will not be allowed to do.

So, if you already didn't in the very beginning, create the /usr/local/Caskroom subdirectory yourself, as the sudo-capable admin user:

cd /usr/local
sudo mkdir Caskroom
chown homebrew:admin Caskroom

Additionally, .app bundles installed via Homebrew will want to be moved into a location outside of /usr/local. Homebrew defaults to /Applications, but I've instead opted to use /Applications/Homebrew for a clean separation.