What is the rationale for the "unix system resources", or /usr
directory, as described here, which duplicates many of the directory names under the root directory /
?
My purpose: I'm installing Oracle JDK for the umpteenth time and decided this time to just put it under /home/user
and I'm just reading around a bit to see if it is a bad idea on a single user machine.
There are the short version and the long version of your answer...
History
Short version:
As your link already said,
/usr
is a place for system-wide, read-only files. So all your installed software goes there. It does not duplicate any names of/
except/bin
and/lib
, but originally with a different purpose:/bin
and/lib
are only for binaries and libraries required for booting, while/usr/bin
and/usr/lib
are for all the other executables and libraries. (now please don't ask about/sbin
, this is the Short Version after all)Nowadays, the distinction between required and not required for booting has diminished, since most modern distros, including Ubuntu, cannot properly boot without several files from
/usr
. And that's why there was a strong movement towards merging/usr/bin
and/bin
. Starting from Ubuntu 19.04/bin
,/lib
(and/sbin
) are just symlinks to their/usr
counterparts, and since Ubuntu 20.04 they don't even exist anymore.But maybe you are confusing
/usr
and/usr/local
? Because yes, there is (and should be) a lot of duplicated directory names. More on that later...Long version:
Back in the 70's, in Unix (yes, Unix, way before Linux), disks had little space (no hard drives yet!), and at a given point the system binaries grew too much in number and size to a point they would not fit a single disk, and developers had to split them across several media and thus create new mount points for them.
/bin
filesystem was full, so they installed the new binaries at.../usr/bin
. And/usr
was, at that time, their... user directory!After this split happened, which is almost embarrassing and often told as a joke/lore, they started to create artificial justifications and criteria to decide what would go to
/bin
and what would go to/usr/bin
. The informal rule was: "essential" stuff go to/bin
, "the rest" goes to/usr/bin
. Same with/lib
. It was not long before/usr
became crowded with system-related directories mixed with actual users' homes. Thus/home
was born, to hold all user-related directories and keep/usr
clean for "system stuff" only.This was long before the FHS exist. When it was created, it embraced and formalized that current tradition and kept the name
/usr
, although at that time it already had nothing to do with "user" anymore. So yes, fancy names like "UNIX Source Repository" or "UNIX System Resources" are all made-up names, and it's too late to rename it anyway. But, as we've seen it, not too late to toss/bin
,/lib
and/sbin
into it. So/usr
is now the main "system" directory."Ok, what about
/usr/sbin
?", you ask. Damn, I was hoping you had forgotten. Ok.../usr/sbin
is for commands that can only be (or are only meaningful when) executed by theroot
user, likemount
andfdisk
."But isn't that almost the same as
/bin
?". Yes, sure, but..."Wait, then why there is an
/sbin
too? That doesn't make any sense!". Well, that's because of... err... humm... hold on...Look, a 3-headed monkey behind you!
Ok, hopefully, you got distracted enough. Moving on...
If you think I'm cheating, yes, I am indeed. But so is the "official" answer: "Essential commands that can only be executed by root and must be available before you even mount
/
." What? Come on! Truth is: the line is indeed blurry, and there are lots of legacy names and paths that just "stuck" and now it is quite hard to get rid of.More on the Case for the
/usr
merge, fromsystemd
docs:And an amazing reading about the
/usr
split and its rationale, by Rob Landley:Understanding the bin, sbin, usr/bin , usr/sbin split
Nowadays
Currently, regarding install directories, your the best way to understand is to think this way:
/usr
- all system-wide, read-only files installed by (or provided by) the OS/usr/local
- system-wide, read-only files installed by the local administrator (usually, you). And that's why most directory names from/usr
are duplicated here./opt
- an atrocity meant for system-wide, read-only and self-contained software. That is, software that does not split their files overbin
,lib
,share
,include
like well-behaved software should.~/.local
- the per-user counterpart of/usr/local
, that is: software installed by (and for) each user. Like/usr
, it has its own~/.local/share
,~/.local/bin
,~/.local/lib
.~/.local/opt
- the per-user counterpart of/opt
So where to install software?
The above list is already half the answer of you Oracle JDK question, at least it gives several clues. The checklist to "Where should I install software X?" goes by:
Is it a completely self-contained, single directory software, like Eclipse IDE and other downloaded java apps, and you want it to be available to all users? Then install in
/opt
Same as above, but you don't care about other users and I want to install for your user alone? Then install in
~/.local/opt
Its files split over multiple dirs, like
bin
andshare
, like traditional software compiled and installed with./configure && make && sudo make install
, and should be available to all users? Then install in/usr/local
Same as above, but for your user only? Then install in
~/.local
Software installed by the OS, or via package managers (like Software Center), and, most importantly, which any local modification might be overwritten when update manager upgrades it to a new version? It goes to
/usr
Notes:
This explains why default install prefix for compiled software is
/usr/local
, and why you should change it to./configure --prefix=$HOME/.local
when installing software for your own user onlyYou may have noticed that all above directories are read-only (except, of course, when you install/remove software). The writable files (like config files) usually go to
/etc
(for system-wide software) and~/.config
(for per-user settings). Although many legacy software (and, unfortunately, some modern too) still use~/.<software-name>
, cluttering your home folder root with dozens of hidden dirs and files.~/.local
and~/.config
are not part of the FHS specification. FHS does not deal with user's home folder. They are an attempt of Freedesktop/XDG, another standard organization geared towards Desktop Environments (like Gnome, KDE, and Unity), to try to set some conventions regarding the structure of the user's home. Not all software adheres to it (for example, distros have only recently included~/.local/bin
in user's default$PATH
, and only if it exists), and no user is forced to follow it, but both gain many interoperability benefits if they do.I hope this helps to clarify things a bit. Feel free to ask anything so I can improve the answer!
(and I also hope purists don't kill me for such an extremely informal language and explanation. It was intentional, and it surely has many inaccuracies, but I do believe it's a good way to make a newcomer have a brief overview understanding about install directories rationales)