💡 The HomeBrew community has added a solution prompt after the user permission error which make this artilce redundent but will be left as personal reference.
This article walks through a solution to leverage HomeBrew on macOS with multiple user accounts. A common use case for this is if you have a "work" and a "personal" user profile. ~The challenge arises when installing a brew package from the secondary user (the user we didn't install brew initially from). We run into the following error or something similar.~
Error: Command failed with exit 128: gitError: The following directories are not writable by your user:/usr/local/lib/pkgconfig/usr/local/share/aclocal/usr/local/share/man/man3/usr/local/share/man/man7/usr/local/share/zsh/usr/local/share/zsh/site-functions
Solution One (Brew cli solution)
sudo chown -R $(whoami) /usr/local/lib/pkgconfig /usr/local/share/aclocal /usr/local/share/man/man3 /usr/local/share/man/man7 /usr/local/share/zsh /usr/local/share/zsh/site-functions
chmod u+w /usr/local/lib/pkgconfig /usr/local/share/aclocal /usr/local/share/man/man3 /usr/local/share/man/man7 /usr/local/share/zsh /usr/local/share/zsh/site-functions
Alternative install - Homebrew docs
If for one reason or another solution one is not effective an alternative is to install homebrew at each user root rather then the system root. The downside to this solution is that the packages will have to be installed individually on in each each user.
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
git clone https://github.com/Homebrew/brew homebrew
Permission denied @ rb_sysopen - /usr/local/var/homebrew/locks/icu4c.formula.lock
sudo chown -R "$USER":admin /usr/local
sudo chown -R "$USER":admin /Library/Caches/Homebrew