Home » Questions » Computers [ Ask a new question ]

Mac OS X: conventional places where binary files should live

Mac OS X: conventional places where binary files should live

I've downloaded an application that is a command-line application, and want to put it somewhere where I can run it from the command-line without having to type the path explicitly.

Asked by: Guest | Views: 374
Total answers/comments: 2
Guest [Entry]

"Core answer: you probably want /usr/local/bin. Depending on how recent your macOS is, you may need to update your default $PATH. See below for further details.

UPDATE 12-01-2018 At some point since I wrote my original answer, Apple changed its default $PATH. As a result, a lot of what I say below is irrelevant to recent Macs. If you type echo $PATH in a terminal, and /usr/local/bin is first, then you can ignore everything below about changing your $PATH.

Original answer

Macs are unusual in this regard. The default $PATH variable for a regular user looks like this:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

By putting /usr/local/bin after /usr/bin and /bin, Mac upends the usual system. Normally, you can put something into /usr/local/bin (say a second Perl interpreter, compiled in some non-standard way), and then a regular user will hit the custom one rather than the system-wide one first. This is good. Users can get variants, but the system stays pure. Given Apple’s default $PATH, however, items in /usr/bin or /bin will get found before anything in /usr/local/bin. (This basically defeats the purpose of installing, e.g., the custom Perl in /usr/local/bin.)

To fix this, you can change the regular user's $PATH by editing the .profile file in the user's home directory. (That file may not exist, if you have a brand-new install. In that case, create it.)

Semi-related: Homebrew provides excellent package management for Macs. By default, Homebrew installs software into /usr/local, but it does so in a way that makes it very easy to remove things and return to a vanilla state later."
Guest [Entry]

"I tend to go with /usr/local. Here's a nice explanation why, which refers to Filesystem Hierarchy Standard (FHS).⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢, which in turn says about /usr/local:

Tertiary hierarchy for local data, specific to this host. Typically
has further subdirectories, e.g., bin, lib, share.⁢"