In Unix and Linux the following conventions are normally observed for the use of the
directories referred to:-
/usr: - Contents are not system-critical
/usr/bin
- Root path of executables installed by the vendor/distro or with
the vendor/distro's package manager
/usr/lib
- Root path of libraries installed by the vendor/distro or with
the vendor/distro's package manager
/usr/include
- Root path of header files installed by the vendor/distro or with
the vendor/distro's package manager
/usr/local/bin
- Root path of executables installed by a system user with
root privelege (You) but not with vendor/distro's package manager
/usr/local/lib
- Root path of libraries installed by You but not with
vendor/distro's package manager
/usr/local/include
- Root path of header files installed by You but not with
vendor/distro's package manager
For the stablity of your system it is important that you install or remove files
in usr/{bin|lib|include}
only with the vendor/distro's package manager,
which you can trust to understand the interdependencies of packages (by version)
and not to mess the system up.
On the other hand the package manager will not install files beneath usr/local
and You may do so, with root privelege. So usr/local/{bin|lib|include}
are
suitable places to install executables|libaries|header files that you build from
source or acquire ready-made but not packaged for your package manager.
These locations are specifically suitable for installing files to be used in building C or C++ software because:-
usr/local/bin
is a default search path for executables.
usr/local/include
is a default compiler search path for header files, so
if your code contains, e.g.
#include <foo/bar.h>
and you have installed usr/local/include/foo/bar.h
, then you don't
need to pass the compiler any -I
option to let it find that header.
usr/local/lib
is a default linker search path for libraries, so
if your program needs to be linked, e.g. with libfoo.a
and you have
installed usr/local/lib/libfoo.a
, then you then you don't
need to pass the linker any -L
option to let it find that library:
-lfoo
will suffice.
However, if you place a shared library, e.g. libfoo.so
in usr/local/lib
(or anywhere, for that matter), the runtime loader will fail to find
it at runtime unless you have first refreshed its shared library cache. You
will need to run:
ldconfig /usr/local/lib
after putting any new shared libraries there.
Don't forget that any binaries you install, without access to source code,
that do not come packaged in your vendor/distro's official repositories stand
an elevated chance of containing malware.