Why are there so many places to put a binary in Linux? There are at least these five:

  1. /bin/
  2. /sbin/
  3. /usr/bin/
  4. /usr/local/bin/
  5. /usr/local/sbin/

And on my office box, I do not have write permissions to some of these.

What type of binary goes into which of these bins?

up vote 473 down vote accepted
  1. /bin (and /sbin) were intended for programs that needed to be on a small / partition before the larger /usr, etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like /bin/sh, although the original intent may still be relevant for e.g. installations on small embedded devices.

  2. /sbin, as distinct from /bin, is for system management programs (not normally used by ordinary users) needed before /usr is mounted.

  3. /usr/bin is for distribution-managed normal user programs.

  4. There is a /usr/sbin with the same relationship to /usr/bin as /sbin has to /bin.

  5. /usr/local/bin is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into /usr/bin because future distribution upgrades may modify or delete them without warning.

  6. /usr/local/sbin, as you can probably guess at this point, is to /usr/local/bin as /usr/sbin to /usr/bin.

In addition, there is also /opt which is for monolithic non-distribution packages, although before they were properly integrated various distributions put Gnome and KDE there. Generally you should reserve it for large, poorly behaved third party packages such as Oracle.

  • 34
    I think this answer does a great job of clarifying a common set of conventions, but this post from Rob Landley is a really great read if you want insight into the nonsense... lists.busybox.net/pipermail/busybox/2010-December/074114.html – Subfuzion Dec 13 '12 at 23:45
  • 3
    refspecs.linuxfoundation.org/fhs.shtml for the canonical current reference. The link by @kojiro is outdated and doesn't have the new spec. – Didier A. May 3 '16 at 18:58
  • 1
    Where do I put a bin I downloaded from the internet? From your description it sounds like it should go in /usr/local/bin or /usr/bin. Is /usr/bin something I should never manually touch, and let only the package manager play with? – Didier A. May 3 '16 at 19:12
  • 2
    @DidierA. put it in ~/bin and add that directory to your PATH as a user... Thanks for the note, I deleted my seriously outdated comment. – kojiro May 3 '16 at 21:22
  • 1
    What's the hierarchy as far as precedence is concerned? I have gcc in /usr/bin for instance, and then I just compiled and installed gcc-7.2 from source and make install put it into /usr/local/bin and now gcc-7.2 seems to take precedence when I call gcc from the command-line. This also makes me wonder....if I want to use my old gcc-4.8 instead of gcc-7.2 how do I do it? – Gabriel Staples Jan 15 at 20:48

I recommend taking a look at the file system hierarchy man page:

man hier

Which is also available online, for instance: http://linux.die.net/man/7/hier

  • This doesn't answer the user's question. – Billy ONeal Mar 5 '11 at 23:54
  • 13
    The man page does contain an entry for each of the bin directories, explaining what goes into them, which was one of the questions. – davitenio Mar 6 '11 at 6:52

The Filesystem Hierarchy Standard entry in Wikipedia helped me answer the same question when I had it, plus it has a very explanatory table.

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. Things like mount, 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.

For further explanation try running the command man hier which should provide a description of the recommended file system hierarchy for your distribution. You may also want to read about the File System Hierarchy on Wikipedia

  • 1
    +1 A really concise explanation if top is a little too much. – CppLearner Aug 24 '17 at 13:09

In the 1970s, UNIX had all official executables in /bin and /usr/bin was a location beneath the users home directories (e.g. /usr/dmr) that was available for any user to store own binaries that might have been of interest for others as well.

The result of this open /usr/bin was a junk yard of undocumented software and so Stephen Bourne wrote a cron script that checked for new binaries every night and removed all binaries that did not have a documentation or that have been updated without updating their documentation as well.

In the late 1970s, /usr/bin was integrated into the OS base distribution and people started to use /usr/local/bin for the purpose of the previous open /usr/bin.

After a while, sysadmins used /usr/local/bin to store non-local software that was imported from the network (e.g. the USENET) and as UNIX companies did not like to repeat the same mistake as with /usr/bin again, there was a file system hierarchy conference around 1987 where all UNIX companies agreed to give up /usr/local/bin and to use /opt/<vendor>/bin instead.

Unfortunately, Linux distros did not follow this decision....

  • While very interesting, none of this even tries to answer the question asked which was not about /opt and not about UNIX but about Linux. This is like answering "Why do cars have 4 wheels?" with "Bicycles have 2! Sadly, cars don't." which doesn't help the OP understand why cars have 4. – terdon Feb 4 '16 at 14:19
  • 1
    If you are unable to use the given explanation as an explanation to the background of Linux and the fact that Linux likes to mimic UNIX , you may be missing the needed background. – schily Feb 5 '16 at 13:29
  • 1
    Interesting, but something I get confused on and which maybe is also only historical. Today, downloading a bin online, and a company bin isn't very different. If Joe Blow makes a program and I download it, why not put it in /opt/JowBlow/bin instead of /usr/local/bin. Is it a matter of trusted provider versus untrusted? It doesn't seem to make sense to me. – Didier A. May 3 '16 at 19:10
  • 1
    I wish I had known this 'exact' history a few years back. a) I wondered why AIX avoided /usr/local, uses /opt/IBM and /opt/ibm and bullfreeware uses /opt/freeware - and why I SHOULD have used a different path (not just /opt/*sbin). As to semi-relevance with Linux - better GNU tools - the default --prefix in auto-tools is /usr/local. Too bad autotools (automake, autoconf, etc. do not follow ... . But we all survive and learn where the distrub. || vendors put their programs. – Michael Felt Nov 24 '16 at 9:00
  • Could we have another one of these conferences? Just this time, EVERYBODY LISTEN! – MemphiZ Sep 6 at 10:54

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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