I would highly recommend checking out the original Homebrew discussion here. I'll summarise a few points from it below.
The default prefix before Apple Silicon (/usr/local) was chosen for a few reasons:
- It's already in PATH. This means that tools installed with homebrew can be accessed without any need to change anything.
- Quite a few build systems already look in
/usr/local, so libraries installed with homebrew can be used by non-homebrew tools.
The Apple Silicon transition came with a change in the default Homebrew prefix. Some of the reasons for this included:
/usr/local is also used by other tools, not just Homebrew. This can lead to potential conflicts.
- Installations in
/opt/homebrew for Apple Silicon and /usr/local for Rosetta 2 can coexist.
- Homebrew tools might not always want to be used by default. A different prefix would make this easier.
There was also an interesting article a while back about some of the potential security risks with /usr/local that you might find interesting.
Other macOS package managers were already using different prefixes (MacPorts with /opt/local and Fink with /opt/sw). MacPorts listed some reasons why they don't use /usr/local here, and Fink has here.
Just to note, although not recommended, Homebrew can technically be installed anywhere. However, pre-built bottles/binaries are only available on the default prefix.
/opt/homebrewwas chosen to allow installations in/opt/homebrewfor Apple Silicon and/usr/localfor Rosetta 2 to coexist and use bottles." – V2Blast Feb 28 '22 at 23:48/usr/local(it's the default for a lot ofmake installsoftware and some software expects to be installed there). – nneonneo Mar 01 '22 at 00:49