osx - How to find out a file belongs to which package in Mac OS X?

06
2014-04
  • hanxue

    Is there a way to find out which Application / package owns or creates a specific file? For example, in Linux these commands will show the package owner

    apt-file /bin/progname
    
    rpm -qf /bin/progname
    
    yum whatprovides /bin/progname
    

    In OS X, a file could be part of a native OS X application, or installed by Macports or Homebrew. These are completely different environments. Are there commands for each environment to check which application / package owns a specific file?

  • Answers
  • slhck

    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.


  • Related Question

    osx - How to install software packages on a Mac? (MacPorts, Fink, anything better?)
  • Ben Alpert

    On my Mac OS X machine, how would you recommend I install command line software and other packages? I've been using MacPorts and it always seems quite slow, presumably because it has to compile the packages on-the-fly.

    I'd much prefer a package management system that has binary packages, saving me the need to compile things every time I want to download something new. I think Fink has binaries for some of the packages, but I usually see MacPorts recommended as the system to use.

    Which do you think works better and why? (Or is there another system that I haven't heard of?)


  • Related Answers
  • slhck

    I used to use Macports because:

    • It is generally more up to date
    • Macports seems to be more common / popular
    • Everyone else I work with uses it

    When I did my own research on this topic when I got my MBP last fall, Macports seemed to be most commonly recommended for reason #1 above, hence reason #2 (and probably reason #3).

    Compiling every package doesn't bother me. It is usually fast enough that it doesn't interfere with work. But you might look into port binaries if you're going to use macports.

    However, I quit using Macports.

    There is also a new tool in this space called Homebrew. I switched from Macports to Homebrew a few weeks ago and I'm pleased as punch. I like:

    • It doesn't install duplicate libraries - it uses the system's existing libs.
    • It installs in the user home directory - no sudo required and backs up to TimeMachine.

    Homebrew works on Leopard or Snow Leopard, though sometimes Formulas need to be modified on Leopard.

    I think all my coworkers have now switched to Homebrew. It is also gaining traction in the Ruby and Erlang (and possibly other OSS?) communities.

  • Legion

    You don't have to pick between the two.

    MacPorts installs software to /opt/local. Fink installs to /sw.

    Both leave the Darwin base system untouched, and the two can co-exist peacefully.

    Fink's binary packages are great, but they aren't always up-to-date. I tend to use Fink when they've got an up-to-date package, and I build from MacPorts if they don't.

    Some packages are only on one or the other, so it's handy to have them both at the ready.

  • dmckee

    Fink partisan here, because

    • The packages of interest to particle physicists (like me!) are very up-to-date
    • I use debian on my linux boxes. The fink command line is a lot like aptitude, and I'm used to the dpkg underpinnings
  • weakish

    If you only install a few programs, anything (fink, macports, homebrew) will be fine.

    But if you are a heavy user, I think only macports is suitable. fink's package is a bit too old. homebrew is a too young project.

    Also, recently I've heard someone using pkgsrc on mac os x. And I may give pkgsrc a try. (I am using macports now, and have 418 ports installed currently.)