How do I run Homebrew as root? Years ago, you could get away with running brew as root just by chowning brew to root, but they removed that feature. So in Homebrew 1.1.6, I used to edit /usr/local/Homebrew/Library/Homebrew/brew.sh to remove the root check (the one that said it's "extremely dangerous") so I could run brew as root.

The newer version of Homebrew still works with that but keeps reverting the brew.sh file back every time after I run brew, even if I chmod 500 it. I could write a script to change it then run brew automatically, but I'm not sure if this will always work and don't want to take chances. Has anyone found a different method to run Homebrew as root?
After making your change to the script, try setting the immutable flag on brew.sh.

chflags uchg /usr/local/Homebrew/Library/Homebrew/brew.sh


I have not tested. As a general rule, I do not give root to applications whose developers are begging me not to.