/usr/bin:

The /usr/bin Directory. /usr/bin is a standard directory on Unix-like operating systems that contains most of the executable files (i.e., ready-to-run programs) that are not needed for booting (i.e., starting) or repairing the system. /usr/bin is one of the major subdirectories of the /usr directory.

/usr/local/bin:

/usr/local/bin is for programs that a normal user may run.

/usr/bin vs /usr/local/bin:

  • /usr/bin is the location for the OS supplied executables that are used by common users.  Ie, not typically core operating system required files, or root user accessed files, but can be.
  • /usr/local/bin is the location for all add-on executables that you add to the system to be used as common system files by all users but, are not official files supported by the OS.
  • usr/bin is where binaries supplied by the OS go. /usr/local/bin is where user supplied binaries go. When you type the name of a command on the command line, the shell searches for said command in the paths contained in the $PATH environment variable in order. A common pattern is to have /usr/local/bin precede /usr/bin in $PATH. This allows you to install alternate versions of binaries and have them gracefully “override” the binaries provided by the OS. And OS updates won’t clobber your user installed packages. This pattern is notably used in OSX by the popular Homebrew package manager tool.
  • For instance, at the time of this writing, OSX El Capitan supplies git version 2.5.4 (in /usr/bin). If you want a newer version, you can use Homebrew to install git version 2.7.0 (into /usr/local/bin). Since /usr/local/bin comes before /usr/bin in the $PATH environment variable, when you issue the command git in a shell, the newer Homebrew version will be used.
  • On fresh new Mac running OSX El Capitan , the /etc/paths file contains the following:
[pastacode lang=”bash” manual=”%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2Fusr%2Flocal%2Fbin%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2Fusr%2Fbin%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2Fbin%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%2Fusr%2Fsbin%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%2Fsbin%0A” message=”bash code” highlight=”” provider=”manual”/] [ad type=”banner”]

which produces the following $PATH environment variable:

[pastacode lang=”bash” manual=”%2Fusr%2Flocal%2Fbin%3A%2Fusr%2Fbin%3A%2Fbin%3A%2Fusr%2Fsbin%3A%2Fsbin%0A” message=”bash code” highlight=”” provider=”manual”/]
  • If you really want to include /usr/local/sbin (listed in your question above), you would put it just before /usr/sbin for similar reasons to above. As for /opt/local/bin and /opt/local/sbin
  • The same explanation applies to /usr/lib vs. /usr/local/lib.
  • The sbin directories contains programs which are generally system administration only. Programs for regular users should never go in them.
  • A few programs are needed during startup, and end up in /bin/ or /sbin/. These must be available before file systems are mounted. And fsck that are required to check and mount files systems must be there.
  • Most packaged programs end up in /usr/bin/ and /usr/sbin/. These may be on a file system other than the root file system. In some cases they may be on a network mounted drive.
  • Local programs and scripts belong in /usr/local/bin/ and /usr/local/sbin/. This identifies them as clearly non-standard, and possibly only available on site.
[ad type=”banner”]

Categorized in: