How to Use Homebrew Across Multiple Users on MacOS
December 13, 2024
Have you ever tried to use Homebrew on your Mac with multiple admin users, only to run into frustrating permission errors? I've been there, and I'll show you the smart way to handle this situation.
Here's the thing: Homebrew isn't designed for multiple users out of the box. If
you're an admin user trying to run basic commands like brew --version
,
you might see this cryptic message:
Homebrew >=4.3.0 (shallow or no git repository)
And when you try to install something? It gets worse. Try running
brew install node
and you'll face a wall of permission errors.
Your first instinct might be to change ownership of Homebrew directories. While this works temporarily, it's not the right approach. Why? Because:
- You'll need to repeat this process for every new user
- It creates potential security risks
- It's just plain messy
Instead of fighting with permissions, let's set up a clean, maintainable solution.
The key is to:
- Designate one user as the Homebrew manager
- Let other users run Homebrew through this manager
Here's how to do it right. Just add this snippet to your ~/.zshrc
file:
source <(brew shellenv)
brew_installer=$(stat -f "%Su" $HOMEBREW_PREFIX)
if [[ $(whoami) != $brew_installer ]]; then
alias brew="sudo -Hu '$brew_installer' brew"
fi
unset brew_installer
That's it! This elegant solution will:
- Automatically detect who owns the Homebrew installation
- Create an alias that runs Homebrew commands as the owner
- Work seamlessly for all admin users
This approach is better because:
- You maintain clear ownership of Homebrew installations
- There's no need to mess with directory permissions
- It's a one-time setup that works for all users
Conclusion
Using Homebrew across multiple users doesn't have to be complicated. With the solution outlined above, you can maintain a clean, secure, and hassle-free setup that works for everyone. Just remember: one installation, one owner, and zero headaches.
© 2025