Differences between the many lib folders in Linux

What's the difference between the many libs in Linux system? (/lib, /usr/lib, /var/lib, /usr/share/lib, etc, etc).

I know it's handled automatically by synaptic whenever I install an application, but in case I want to be a Linux developer, I sure need to know where to put my application libs in the system.


Typically, your software will be installed either under /, or /usr, or /usr/local. This is called the "prefix". / is typically reserved for the most critical operating system programs. /usr/ is reserved for use by package managers. Therefore, when you write software, it is most polite to set it up so that the prefix will be /usr/local. Then this can be overridden when someone packages it for a distribution.

Notice I'm not specifically talking about "lib". There are several common subdirs under the prefix, lib being just one of them. "bin" is used for executables, "share" for data files, "lib" for shared libraries and so on. So if your program is a library, you can install it by default to /usr/local/lib. If it's a normal program, you can have it install to /usr/local/bin with your data files in /usr/local/share. The important thing is that you make it so the prefix is selectable at compile time. Some may prefer to install to /usr rather than /usr/local or vice-versa.


There is also a standard that describes linux/unix filesystem hierarchy. It can be found at: http://www.pathname.com/fhs/. This is meant mainly for distribution developers, but I don't see any reason who a user/developer should not be aware of it.