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:

Instead of fighting with permissions, let's set up a clean, maintainable solution.

The key is to:

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:

This approach is better because:

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