2

I often use dpkg -S <file> on Debian to get the package name that installed <file>.

However, using brew I cannot find this option anywhere?

How can I obtain the Brew formula that installed a given binary?

3

The brew whence external command takes an executable and looks up the Homebrew formula from where the executable comes.

Installing

To install the brew whence command, run:

$ brew tap claui/whence

Running

To run brew whence, pass it an executable:

$ brew whence python3
Executable                Comes from    
==========                ==========    
/usr/local/bin/python3    → python 3.7.7

Or pass it several executables at once:

$ brew whence 7z git-shell lzgrep
Executable                  Comes from
==========                  ==========
/usr/local/bin/7z           → p7zip 16.02_2
/usr/local/bin/git-shell    → git 2.26.0
/usr/local/bin/lzgrep       → xz 5.2.5

More information

For more information and examples, run brew help whence:

$ brew help whence

Full disclosure

Full disclosure: I wrote this command.
It is not part of Homebrew proper but you can inspect the code yourself.

| improve this answer | |
  • 1
    Not a user of Homebrew as I prefer MacPorts, but this is really cool. +1 – Allan Apr 5 at 5:27
  • 1
    Thank you. So, basically what your command does, is to go into /usr/local/bin, search for a symlink matching the supplied filename, follow the symlink into /usr/local/Cellar to get the name of the formula that's in the absolute path, e.g.: /usr/local/bin/ragg2@ -> ../Cellar/radare2/4.3.1/bin/ragg2? – Shuzheng Apr 5 at 5:33
  • @Shuzheng Mostly, yes. It also honors /usr/local/sbin, and I plan to add support for Cask- and npm-installed executables. – Synoli Apr 5 at 19:30
  • You may also want to check out github.com/Homebrew/homebrew-command-not-found. It provides a brew which-formula command, which may support not-yet-installed packages, too. (I didn’t know it existed until after I wrote brew whence.) – Synoli Apr 5 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .