How to Install a Library When I Have Its Source Code? [Duplicate]

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?

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.

2
Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest