43

The Homebrew installation page says:

This script installs Homebrew to its preferred prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon and /home/linuxbrew/.linuxbrew for Linux) so that you don’t need sudo when you brew install. It is a careful script; it can be run even if you have stuff installed in the preferred prefix already. It tells you exactly what it will do before it does it too. You have to confirm everything it will do before it starts.

Why does Homebrew choose /opt/homebrew as the installation prefix for Apple Silicon Macs instead of /usr/local like it does for Intel Macs?

Nimesh Neema
  • 51,809

2 Answers2

43

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.

Haren S
  • 625
  • 9
    I like the first comment in each of the Homebrew reasons - they rather cancel out. – mmmmmm Feb 27 '22 at 13:08
  • Can you force the pre-built bottles/binaries to be installed into a custom prefix as well? – JonathanReez Feb 28 '22 at 19:30
  • No, not really. Often, the prefix might be hardcoded into compiled files during build time. There's no easy way of changing this short of building locally in the custom prefix. – Haren S Feb 28 '22 at 22:51
  • Related entry from the FAQ: "Why is the default installation prefix /opt/homebrew on Apple Silicon? The prefix /opt/homebrew was chosen to allow installations in /opt/homebrew for Apple Silicon and /usr/local for Rosetta 2 to coexist and use bottles." – V2Blast Feb 28 '22 at 23:48
  • 3
    I'm actually happier that they made this change. I've been resisting using Homebrew precisely because I have tons of random stuff under /usr/local (it's the default for a lot of make install software and some software expects to be installed there). – nneonneo Mar 01 '22 at 00:49
10

From the Homebrew FAQ :

The prefix /opt/homebrew was chosen to allow installations in /opt/homebrew for Apple Silicon and /usr/local for Rosetta 2 to coexist and use bottles.

This allows the installation and execution of two Homebrew versions simultaneously on Apple Silicon, one for ARM and one for Intel under Rosetta. See further here