How to programmatically get the list of directories that brew installs to?

1

I am writing a script that automates setting up my mac dev environment. I want to place the directories that brew installs first on my path, so that the default system commands are overridden by brew installs. I know brew installs to /usr/local/Cellar, /usr/local/Caskroom and places symlinks in /usr/local/opt/ but I want to get this information programmatically in case the default directories that brew installs to change in the future.

user1124109

Posted 2020-02-06T22:02:49.943

Reputation: 11

Answers

0

Cellar is the default directory used by brew for quite a while now, and the same with Caskroom for brew cask. These are very unlikely to change as it would result in a significant amount of migration work for both the developers and the users, for very little benefit.

More interesting is the installation prefix - namely where those two folders are located. Those could very well change if Apple decides to play around with /usr/local/ in the future.

If you want to get the current prefix, run brew config | grep HOMEBREW_PREFIX.

As to the actual symlinks that point to the install apps, these are placed into /usr/local/bin (again, respecting HOMEBREW_PREFIX, with /usr/local/bin being placed into your path).

If Apple somehow restricts the use of /usr/local, everything could be repointed by modifying HOMEBREW_PREFIX to a different directory, with the bin winding up in your path, and Homebrew using the Cellar and Caskroom directories under the new prefix.

Mikey T.K.

Posted 2020-02-06T22:02:49.943

Reputation: 3 224