How to find out a file belongs to which package in Mac OS X?
Solution 1:
It's a little late, but perhaps it will be of help to others.
You can use the pkgutil
command.
For example, if you want to know what package the "less" command belongs to run:
pkgutil --file-info /usr/bin/less
Which will output something like:
volume: /
path: /usr/bin/less
pkgid: com.apple.pkg.BaseSystemBinaries
pkg-version: 10.7.0.1.1.1309742044
install-time: 1310407891
uid: 0
gid: 0
mode: 755
To list all files contained in a package, com.apple.pkg.BaseSystemBinaries
in our example, run:
pkgutil --files com.apple.pkg.BaseSystemBinaries
I know this tool has been present since OS X 10.6.
Solution 2:
This is not really possible since there's no standardized package management.
Unless you configured MacPorts or Homebrew differently, you'll always find their executables in a location that nobody else uses. Since MacPorts and Homebrew do not run under a separate user account, the files they create will always be owned by your user or root
.
What's left is that you can only try to guess based on the executable location. Here are some rules:
MacPorts uses
/opt/local/bin
and/opt/local/sbin
for executables, everything prefixed under/opt/local
.Homebrew uses
/usr/local/bin
for executables, everything else under/usr/local/
.Other applications should create their own directories somewhere under
/usr
, e.g./usr/local/git/bin
for the Git OS X installer or/usr/X11/bin
for X11.Some system frameworks symlink to
/usr/bin
, e.g.rake
points to/System/Library/Frameworks/Ruby.framework
No application should ever use
/bin
or/sbin
. No third party application (i.e. anything not an OS X framework) should use/usr/bin
either.
Solution 3:
To collect them in one place for the two other package managers on OSX:
For MacPorts (as mentioned by Neil in comments above):
port provides /opt/local/bin/progname
For Brew it's not so simple but one can usually find the package using:
ls -la /usr/local/bin/progname
Which should show a softlink that contains the package name, or else one can use other suggestions from one of these questions.