I want to add my own library to use in c compiling, but don't really know where ubuntu stores it.

  • 5
    It stores in /usr/lib & /usr/include – karthick87 Dec 15 '10 at 9:54
  • i did find my library's in /usr/include how should i go with putting them in? should i just put a header file and a c file near it or should i write the header and the function together in one .h file? – david25 Dec 15 '10 at 10:06
  • 3
    Libraries and headers are different things, /usr/include does NOT contain libraries, it contains headers which are definitions of functions/objects available from libraries. The question should be improved, it's hard to understand what are you trying to achieve. – João Pinto Dec 15 '10 at 15:04

Based on your comments to your question, I think what you are really asking is "How do I install a custom library I wrote and where should I put it?"

In general, things built locally for others on the machine to user are put into the /usr/local tree. The header file should go into /usr/local/include. The compiled library should go into /usr/local/lib. The .c file is not part of the library, it is part of the source and not something normally not installed for the use of the end user. You will need root access to put files in either of these locations.

To build the library, you will need to build first decide if you want a static or dynamic (shared) library. More information on creating a shared library can be foundin section 3.4, Creating a Shared Library at http://www.linux.org/docs/ldp/howto/Program-Library-HOWTO/shared-libraries.html. (They also have recommendation about where to put stuff -- most developers will have an an opinion or three :-) )


Depending on library, ubuntu stores its libraries mainly in three locations

  1. /lib
  2. /usr/lib
  3. /usr/local/lib

Following is from File System Hierarchy Standard


The /lib directory contains those shared library images needed to boot the system and run the commands in the root filesystem, ie. by binaries in /bin and /sbin.


/usr/lib includes object files, libraries, and internal binaries that are not intended to be executed directly by users or shell scripts. [22]

Applications may use a single subdirectory under /usr/lib. If an application uses a subdirectory, all architecture-dependent data exclusively used by the application must be placed within that subdirectory.

/usr/local/lib contains local libraries i.e one specific for this system but I can not find references to /usr/local/lib in FHS, it only contains explanation for /usr/local.


Ubuntu follows Filesystem Hierarchy Standard (http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard), regular applications libraries should be stored under /usr/lib .

Please note that developing/managing libraries is not a trivial subject, you should read some more detailed documentation, here is a nice tutorial: http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html


You should tell the compiler, where it can find your library. Assumed, the path to your library is "/path/to/lib/libfoo.a", you could compile and link your program "hello.c" like this:

gcc -L/path/to/lib -lfoo hello.c

This is not specific to Ubuntu, actually all C-compilers I know support those flags.


In Ubuntu they are found in /usr/include.

  • 1
    Header files are in /usr/include. The actual binaries for a library are not stored there. Headers may be considered part of a library, but they have to be installed separately, and they are use to compile programs that use a library. Once a program that uses a library has been compiled, it doesn't need or use the header files anymore. – Eliah Kagan Aug 30 '13 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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