Let me answer that from the MacPorts perspective I come from, as these problems of co-existing software management tools are not unknown there. Most importantly, there simply is no way to remove /usr/local
from the default compiler search paths. This may lead to problems with some builds, especially during a multi-architecture +universal
compilation.
In the beginning of the project many years ago, MacPorts switched to /opt/local
in order to avoid problems with other software. Total isolation from /usr/local
does not seem to be possible at all by compiler configuration flags alone. Unfortunately, Homebrew developers deliberately ignored this and chose /usr/local as their default. While it sounds like a good idea as it would be already listed in PATH, in the default configuration /usr/local/bin
only occurs after /usr/bin
, making it impossible to overwrite any command line tools. So there is no advantage of using /usr/local
at all.
Best solution is to either install Homebrew to any other path (for example /opt/homebrew
), or to rename /usr/local temporarily before building and rename it back afterwards:
sudo mv /usr/local /usr/local.off ... # do your compilation work sudo mv /usr/local.off /usr/local
As a side note for the future, while MacPorts in its current version is already using a sandbox for all builds, there are improvements in this area coming for version 2.3.0 or later. The new trace mode currently in development would allow to limit all file access to those files required for the particular build task only, hiding locations like /usr/local
and /sw
completely from the build process. However, that won't help with other tools unless they adopt this feature as well.