26

What is the difference between /lib and /usr/lib and /var/lib? Some of the files are symbolic links that "duplicate" content of other directories.

2 Answers 2

29

Someone else can probably explain this with much more detail and historical reference but the short answer:

/lib

is a place for the essential standard libraries. Think of libraries required for your system to run. If something in /bin or /sbin needs a library that library is likely in /lib.

/usr/lib

the /usr directory in general is as it sounds, a user based directory. Here you will find things used by the users on the system. So if you install an application that needs libraries they might go to /usr/lib. If a binary in /usr/bin or /usr/sbin needs a library it will likely be in /usr/lib.

/var/lib

the /var directory is the writable counterpart to the /usr directory which is often required to be read-only. So /var/lib would have a similar purpose as /usr/lib but with the ability to write to them.

15
  • 10
    Just to improve a bit - it all comes from Filesystem Hierarchy Standard. The definition is a bit old-ish now but still offers interesting insight. pathname.com/fhs/pub/fhs-2.3.html
    – Fiisch
    Nov 30, 2021 at 7:50
  • 2
    This answer is at least 15 years late, yeah, "historically" it's correct but Linux distros haven't had /bin /sbin and /lib for many years now and all three are linked to the appropriate /usr directories. And /var/lib normally holds transcient data, you may as well delete completely and the system won't be affected. Lastly it's probably the 150th time this question has been asked. Dunno why people jump to answer it again and again. Nov 30, 2021 at 8:01
  • 15
    @ArtemS.Tashkinov Sorry, but there's a whole lot of inaccuracies in your comment. "15 years" is way off, Fedora made the move to /usr in 2012 and it certainly wasn't the last major distro to do so (if not the first). /var/lib is definitely not for transient data, at least not on most distros. Deleting it is going to have disastrous consequences on a typical system (destroying the yumdb/rpmdb and breaking the package manager with no way to repair it, nuking the default storage location of various SQL databases or VMs with precious data, etc.)
    – TooTea
    Nov 30, 2021 at 8:21
  • 16
    noteworthy: "as it sounds, a user based directory" - usr sounds like "user", but it actually stands for Unix System Resources
    – kubi
    Nov 30, 2021 at 10:48
  • 15
    @kubi That smells of Folk Etymology or Convenient Backronym to me; it's not even a good description of its role. Wikipedia cites these notes from Dennis Ritchie describing the origin as "a directory '/usr' which contains all user's directories, and which is stored on a relatively large, but slow moving head disk".
    – IMSoP
    Nov 30, 2021 at 16:11
15

Files in /lib and /usr/lib are supposed to be mostly read only and identical between systems. (If it was a container image, they could be fully read only and shared between systems; on a stand alone system, they need to be writable to install updates.)

Files in /var are specific to the local system and frequently contain data that is generated by system operation.

Typically distribution versions of templates for config files can be found in /usr/lib and can be used to create localized versions of config files in /etc or possibly /var.

I'm not sure why there would be duplicate files between /lib and /usr/lib, more likely they are symlinks and not duplicates. (There are no such files on my current system, and only one symlink.)

Historically directories like /usr/lib /usr/bin were actually created because /usr was on a separate disk and things were put there because /bin and /lib were on the root disk which was too small to hold everything, and what was left on the root disk were things critical to boot far enough to mount /usr. Of course, this concept is obsolete, and there is a movement to merge them.

6
  • I've used systems that had /bin -> /usr/bin. Why not /lib -> /usr/lib?
    – Joshua
    Nov 30, 2021 at 19:05
  • That is happening too probably.
    – user10489
    Nov 30, 2021 at 23:29
  • It's happening, but slowly. Mostly because distribution maintainers tend not to throw something away that still works, the added benefit to moving everything to /usr/lib is debatable at best, there may still be large networks where /usr is mounted from a network share, and most importantly manually going through up to thousands of packages to see if they might cause edge case issues with the /lib -> /usr/lib move is more trouble than it's worth. Dec 1, 2021 at 7:56
  • From what I've read the /bin -> /usr/bin move has been applied and backed out a few times for exactly that reason too.
    – user10489
    Dec 1, 2021 at 12:20
  • 1
    Ubuntu since 19.10 makes /bin, /lib, /lib64 etc. all symlinks to those in /usr. Debian does so since Buster. It's a universal move now that we rarely have separate mounts for / and /usr.
    – iBug
    Dec 1, 2021 at 12:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .