I'd highly recommend checking out the original Homebrew discussion here. I'll summarize a few key 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 needing 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 brought 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.