MacOS – How to install homebrew to /usr rather than /usr/local

high sierrahomebrewmacos

I'm wondering if it is possible (and if so, how) to install Homebrew package manager to /usr directory rather than /usr/local directory. I have macOS High Sierra.

Best Answer

One way is to modify the install.sh script in homebrew git source and change HOMEBREW_PREFIX to point to whereever you want homebrew to install.

In my case, I've decided to use /usr/local2, because of some restrictions on /usr/local in OSX Catalina, so modify install.sh with HOMEBREW_PREFIX=/usr/local2 and HOMEBREW_REPOSITORY=/usr/local2/Homebrew before running ./install.sh.

Two problems you have to watch:

  1. Some packages insist on installing in /usr/local unless you manually hunt down and modify the source (not trivial)
  2. Installing in a directory that already has similar/equal files can overwrite them and render your system unstable. Especially /usr, where a lot of system commands exist there, which you never want to replace at all.