/usr/bin vs /usr/local/bin on Linux
And on my office box, I do not have write permissions to some of these.
What type of binary goes into which of these bin s?
There are fewer places nowadays, since /bin was merged with /usr/bin and /sbin was merged with /usr/sbin – see The Case for the /usr Merge.
@Pacerier ~/bin is for the current user only. For example in multiuser Linux servers where you are not an admin that’s the only way to «install» stuff for yourself.
5 Answers 5
- /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.
- /sbin , as distinct from /bin , is for system management programs (not normally used by ordinary users) needed before /usr is mounted.
- /usr/bin is for distribution-managed normal user programs.
- There is a /usr/sbin with the same relationship to /usr/bin as /sbin has to /bin .
- /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.
- /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.
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
refspecs.linuxfoundation.org/fhs.shtml for the canonical current reference. The link by @kojiro is outdated and doesn’t have the new spec.
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?
@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.
I found the answer to the first part of my question here: superuser.com/a/238993/425838. Precedence is based on order in the system PATH variable, and echo $PATH for me shows /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games , which means that executables in /usr/local/bin take precedence over the ones in /usr/bin which take precedence over the ones in /bin .
I recommend taking a look at the file system hierarchy man page:
which is also available online, for instance: http://linux.die.net/man/7/hier. Relevant portions have been copied below. Depending on your system, it may say something different.
Name
Description
- A typical Linux system has, among others, the following directories:
- This directory contains executable programs which are needed in single user mode and to bring the system up or repair it.
- Like /bin , this directory holds commands needed to boot the system, but which are usually not executed by normal users.
- This is the primary directory for executable programs. Most programs executed by normal users which are not needed for booting or for repairing the system and which are not installed locally should be placed in this directory.
- Binaries for programs local to the site.
- Locally installed programs for system administration.
- This directory contains program binaries for system administration which are not essential for the boot process, for mounting /usr , or for system repair.
The man page does contain an entry for each of the bin directories, explaining what goes into them, which was one of the questions.
@BillyONeal Probably a better answer than others because it does answer the question, moreover gives a quick reference command as well.
The Filesystem Hierarchy Standard entry in Wikipedia helped me answer the same question when I had it, plus it has a very explanatory table.
/bin Essential command binaries that need to be available in single user mode; for all users, e.g., cat, ls, cp. /usr/bin Non-essential command binaries (not needed in single user mode); for all users. /usr/local Tertiary hierarchy for local data, specific to this host. Typically has further subdirectories, e.g., bin, lib, share /usr/sbin Non-essential system binaries, e.g., daemons for various network-services. /sbin Essential system binaries, e.g., fsck, init, route.
1 Retrieved on June 19, 2019; permalink.
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
«Local programs and scripts belong in /usr/local/bin/ and /usr/local/sbin/» — You mean local programs as in «not at all part of the OS, but I decided to install them and want to use them»?
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//bin instead.
Unfortunately, Linux distros did not follow this decision.
Introduction
Linux is a Unix-like, open source and community-developed operating system for computers💻, mobile devices📱, servers🖥 and embedded devices. Whether you know it or not, Linux is everywhere from your smartwatch⌚ to self-driving cars🚗. Linux was known for being less intuitive and only for people who do tech-stuff but time has changed ⌛. Linux has something for everyone.
It has GIMP as a Photoshop alternative , Gedit as a Notepad alternative , VLC media player as a Windows media player alternative and many such software alternatives. If you have been a Windows user💻 and have switched to Linux to look super nerdy🤓 or to crack linux jokes(yeah some people do), you might find it hard even to do basic things like copying, moving and deleting files or switching between directories. Let’s say you’re exploring Linux for the first time, and you happened to be in the top level root directory (/). Now if you typed ls , you may come across a lot of the stuff which you think you know about. But it’s highly likely that you interpreted it wrong. For example, /bin might sound analogous to the Recycle Bin in Windows but that’s not the case. Both are way different. Although most of the modern Linux distributions come with the GUI, the real power of Linux is in it’s CLI👨💻 and not GUI.
Linux File Hierarchy Structure
Linux file hierarchy structure describes the directory structure and it’s contents in Unix and Unix-like Operating systems. It is maintained by Linux Foundation. You can learn more about it here.
Difference between /bin and /usr/bin
man hier | grep -E '/bin$|^.(/bin)' -A2
snake@Snake:~$ man hier | grep -E '/bin$|^.(/bin)' -A2 /bin This directory contains executable programs which are needed in single user mode and to bring the sys‐ tem up or repair it. -- /usr/X11R6/bin Binaries which belong to the X-Window system; often, there is a symbolic link from the more traditional /usr/bin/X11 to here. -- /usr/bin This is the primary directory for executable programs. Most programs executed by normal users which are not needed for booting or for repairing the system and which are not installed locally should be -- /usr/local/bin Binaries for programs local to the site.
The output says it all.
So, that’s all for the blog. I hope you understood it.
.
.
.
.
Well, not really. There’s a good historical reason for this split. Back in time, when Ken Thompson and Dennis Ritchie were developing UNIX on a PDP-11, they used a pair of RX05 disks of 1.5 MB each. As the Operating system grew bigger in size, first RX05 disk got filled up. So, a second RX05 disk was used and the mount was created by the name /usr . All the directories like /bin, /sbin, /tmp were replicated under it. So, First RX05 disk contained the binaries which would help in its bootup(like single-user mode).
And the Second RX05 disk contained a lot less and least used binaries during that time until multi-user mode came into existence. As the time passed the storage capacity on a disk drive increased exponentially and in this modern world, even the throwaway disk will have at least multi-gigabyte capacity. So, for a person born in this era, it’s hard to imagine why the split would be made.
What about /usr/local/bin ?
/usr/local/bin contains binaries of the third-party apps we install. Any local executable that didn’t come with the Linux install may get it’s place here.
Differences between /usr/bin and /usr/local/bin
What are the main differences between /usr/bin and /usr/local/bin ? I have noticed on different machines that, when I install Vim (or sometimes it is already installed), sometimes it is located in the local component, and sometimes it is not. What is the difference between the two, if any?
1 Answer 1
4.9.1. Purpose
The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable amongst a group of hosts, but not found in /usr.
Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr.
Structure is similar to /usr , but is for site local software. Something you build yourself, or want to install an alternative version. configure scripts call this the prefix, often defaulting to the equivalent of ./configure —prefix=/usr/local . In contrast, distribution provided «system» packages tend to use /usr . So by default, your custom-built /usr/local/bin/vim will not be accidentally overwritten when the system package is upgraded.
As system administrator, you should understand how software is being installed, because your responsibilities likely include maintaining it. Query any package database for the files in question. Find out who’s been running make install from source.