1

I want to include some libraries in my project like json-glib, beecrypt or libffi.
Usually, I install all the libraries using sudo apt-get install XYZ.
But sometimes, I get a .tar file of any library which I extract at some place on my desktop.
I don't know how to install these type of libraries for which I have the source code. I get the installed files in /usr/include or sometimes in /usr/lib folder when I install using the above command written.
How to do it in case of source code?

Eric Carvalho
  • 54,385
hellodear
  • 4,673
  • Note that /usr/include contains the headers for the library, which you need if you wanted to write a program/library that uses this library and is only used during compilation, and that /usr/lib contains the library itself, which is needed to run something that uses that library. Also, note that some buildsystems install into the /usr/local prefix (which I prefer) instead of the /usr prefix. – saiarcot895 Jul 24 '14 at 13:53
  • I disagree that this is a duplicate of the aforementioned question. A specific component is present here: the specification of the path for the library. This question has blessed my day! :) So thanks @hellodear Chandramouli for useful contribution. – loved.by.Jesus Apr 20 '16 at 13:31
  • I agree and Sharath answered that particular part well ... – oemb1905 Dec 08 '17 at 01:47

1 Answers1

3

The recommended way to install a library which was downloaded in its source code form is:

  1. Assuming you are in the home folder, extract the .tar, .tar.gz, .tar.bz2, .tar.xz file using,

    tar xf source_filename

  2. Go to the folder /home/some_user/libxxx/ (the folder into which the previous tar command extracted the files)

  3. Run,

    ./configure --prefix=/usr/local

    make

    sudo make install

This installs the library in '/usr/local' which is the recommended path according to the convention when you are not installing a software via any package manager. Also, this will not pollute the existing libraries in '/usr/lib' which makes maintenance easy in case you wish to uninstall the library in future.

  • what is the difference if I will put the files in usr/local and /usr/lib and /usr/include? I am new to ubuntu. Elaborate this thing. Thanks. – hellodear Jul 25 '14 at 05:07
  • /usr/lib is the path for compiled libraries, whereas /usr/include is the path where the C/C++ header files are stored which contain function prototypes to access the libraries. As already explained, there is no harm if you install the custom library in /usr/lib or /usr/local, either should work. For custom libraries, /usr/local path is recommended only from administration perspective. Hope am clear. – moosambi2020 Jul 25 '14 at 12:53