In the root directory, we can find several 'lib' subfolder, for example, /lib, lib32, lib64, /usr/lib, /usr/lib32, /usr/local/lib.

What are their differences?

  • If that question is not specific enough for you, edit this one with any particular questions you have and we'll vote to re-open it.
    – Flimm
    Apr 15, 2013 at 10:23
  • @Flimm Agreed. The below answer was provided during/while I was looking at the new edits in the other question and seems to be more detailed. Apr 15, 2013 at 10:39
  • @Flimm FWIW, I like the fact that this question is focused just on the lib directories, and I think it's useful on its own. Also this question isn't specific to 12.04, there might be a better tag for this.
    – jrh
    Nov 15, 2018 at 18:26
  • Also related: What is /usr/lib/i386-linux-gnu/ for?
    – jrh
    Nov 15, 2018 at 18:45

1 Answer 1


/lib contain "essential" libraries that may be needed even in single-user (admin-only) mode and without /usr mounted

/usr/lib are the libraries for the normal user-programs, that mostly can be found under /usr.

/usr/local/lib are the libraries for locally installed programs and packages ie. things you've compiled and installed from source-packages yourself.

In addition to shared and static libraries which are the lib-directories main purpose, you may also find some hierarchies (with their own lib, bin, include and so on) for some larger packages under them.

lib32 and lib64 are used on 64-bits systems to separate libraries for 32-and 64-bits.

  • for the specific 'lib' file in '/usr/local/lib', how can I include it in my program ? Thanks
    – tqjustc
    Apr 15, 2013 at 17:09
  • 2
    The command ldconfig updates the system's cache over libraries, so after installing a new library, you should run this. There is also a config-file /etc/ld.so.conf which specify where ldconfig will look for new libraries, and you can add unusual library-location - like libraries with the actual lib-files in their own subdirs. /usr/local/lib should already be there, so if your library was installed directly under /usr/local/lib, running ldconfig should be enough. More in part #2 Apr 16, 2013 at 13:19
  • 2
    Now the system knows where the library is, but often you need to specify unusual libraries to the gcc and g++ compilers and linker as well. In your program you use #include to specify the library's header file. To compile: "gcc -Wall -I/path/to/includefile -c myprogram.c" Here it's probably /usr/local/include, which should be found anyway. To link with the library, you would use the command "gcc -L/path/to/library -lnameoflibrary -lotherlibraries myprogram.o" Again, /usr/local/lib should be found automatically, but if the lib was in a subdir, you surely would need to specify. Apr 16, 2013 at 13:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.