Is there a way to figure out which brew package provides a given file (like apt-file on Ubuntu or pkgfile on Arch)?

I'm not talking about querying which locally installed package owns a file on my system, I have a particular file that I need installed (/usr/local/lib/libboost_python.dylib to be specific) and want to know which remote package would provide that file.

  • Turns out that file is provided by boost as long as you configure it with --with-python. Would still be nice to know if there was a way to query which files are provided by which files... – mgalgs Jul 12 '14 at 3:58
  • FWIW this is now provided by boost-python instead. – Tim Smith Jul 2 '15 at 15:48

There is not. Nothing in Homebrew maintains a list of files that a package is allowed or expected to install.


While there is not apt-search like tool that allows one to find public homebrew packages that could provide a file, many brew packages are based on a linux or unix counterpart. You can search the Debian package website to find the needed package.

Example for finding package that provides file goocanvas.pc


Returns libgoocanvas-dev

brew search has no results for libgoocanvas-dev or libgoocanvas but it does have a goocanvas package.

You can define a command ineed as follows that would return a list from debian.org using ineed goocanvas.pc:

ineed() {
echo -en $(echo \
    $(curl -s "https://packages.debian.org/search?suite=default&section=all&arch=any&searchon=contents&keywords=$1") \
       | sed 's%</*tr>%\\n%g') \
    | grep 'class="file"' \
    | sed 's/<[^>]*>//g' \
    | column -t \
    | grep --color -i -w "$1"

As stated in this answer you can do ls -l /usr/local//lib/whatever and see where the symlink points to.

  • Or ls -l $(which somecommand) – mivk Sep 24 '17 at 12:29

Though there isn't a built-in brew command to search for a specific file, you can use a combination of brew list and brew list <formula> to get the answer. It takes a while, but if you're doing some cleanup and have to answer this kind of query more than once, you might do what I have done sometimes: make a catalog of files by package:

# make a catalog of Homebrew-installed packages by package
brew list --formula |\
  while read formula; do
    brew list $formula |\
    while read file; do
      echo -e "$formula\t$file" # need -e to expand \t

If you redirect the output of this script to a file, you can use it to search for the package that provides the file of interest.

  • 2
    This is good, but it searches currently installed packages. The question is asking about searching packages not installed. – Burhan Ali Mar 31 '18 at 11:36
  • I like this. FWIW, brew now issues a warning: Warning: Calling brew list to only list formulae is deprecated! Use brew list --formula instead. – John Schmitt Dec 21 '20 at 20:56

Here is the one-liner I have in my bin directory for exactly this purpose:

$ cat ~/bin/brewpkg

which -s $1 ; if [ $? -eq 0 ] ; then ls -lF `which $1` | sed -n 's/^.*\/Cellar\/\([^\/]\{1,\}\)\/.*$/\1/ p' ; fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.