Packaging: /usr/lib vs. /usr/lib/*-linux-gnu

Solution 1:

In Debian and Ubuntu, and indeed the FHS, /usr/lib and variants are "owned" by the vendor. In this case, that means your distribution. You should not be placing files there yourself at all. Of course you can do as you like, but tooling (such as dpkg) will just overwrite files you place there without prompting, because the system by design considers these spaces for distribution packages only. Your system is yours to break as you wish, but you also get to keep the pieces :-)

The space reserved for the system owner/administrator to place extra system-wide libraries is /usr/local/lib. This is in the FHS, so should be available and configured across all standards-respecting distributions. Upstream software should have make install place libraries there by default.

...is there a functional or philosophical difference between placing a library in /usr/lib versus placing a library in /usr/lib/{x86_64,i386}-linux-gnu?

Distribution packages that use /usr/lib can't have different architectures installed at once (such as i386 vs. amd64), which as others have pointed out is useful for desktops running both 32-bit and 64-bit software, and for developers running code built for other architectures by emulation. This is the sole reason for the multiarch subdirectories.

The same applies to libraries you install yourself. Whether you do that in /usr/lib or /usr/local/lib, you won't be able to have multiple architectures supported concurrently. You can always add multiarch paths like /usr/local/lib/{x86_64,i386}-linux-gnu to /etc/ld.so.conf.d/ to enable that of course.

Solution 2:

You are right, in a traditional system all libraries were installed in /usr/lib. As you already mentioned, the fact that users like to execute 32-bit binaries on 64-bit platforms is one of the reasons to separate libraries by their architecture. This approach is known as Multiarch (at least in the Debian world).

In addition, developers like to install libaries of other architectures (like ARM) to cross-compile their applications.

The FHS recommends to put 32-/64-bit libaries into the folders /usr/lib{32,64}. This approach is kind of inflexible as there is no support for other architectures (e.g. ARM). There even exist multiple 64-bit ABIs which are not compatible with each other and would end up in the same folder.

Further information:

  • Debian Wiki: Multiarch Implementation
  • Ubuntu: Multiarch Spec