How to install libraries manually in Linux

I have already written an article with step by step instructions to load modules from kernel during boot stage and also a guide to blacklist any module during boot up stage.
Shared libraries relies heavily on concept of libraries. These are the collection of software that are re used by other programs. This avoids having to rewrite the code for functions that are used repeatedly.
Software libraries can be linked in two ways:

  1. Statically
  2. Dynamically



These are compiled together with a program to produce a single piece of executable code. this can have advantage of producing executable code that runs quickly. However this disadvantage is that the resulting code tends to be long and so uses large amount of system resources.


These are also shared libraries and are loaded into memory as they are needed. This means that the code compiled with dynamically linked libraries has a smaller memory footprint then if it were linked statically.
Shared libraries are frequently updated. Installing new libraries means that you need to maintain the software that depends on these libraries. We do this in order to avoid or resolve dependencies and conflicts.
To list the shared libraries

# ldd /bin/ls =>  (0x00007fffa9bff000) => /lib64/ (0x0000003f64600000) => /lib64/ (0x0000003f63600000) => /lib64/ (0x0000003f66e00000) => /lib64/ (0x0000003f6da00000) => /lib64/ (0x0000003f62e00000) => /lib64/ (0x0000003f62a00000)
        /lib64/ (0x0000003f62600000) => /lib64/ (0x0000003f63200000) => /lib64/ (0x0000003f73200000)


Install a library manually

To install a library file you need to copy the file inside /usr/lib and then run ldconfig (as root). It will install any new library in that directory

# ldconfig -n -v /usr/lib

ldconfig  creates  the  necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/, and in the trusted directories (/lib and /usr/lib).  The cache is used by the run-time linker,  or ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated.
ldconfig  will attempt to deduce the type of ELF libs (i.e., libc5 or libc6/glibc) based on what C libs, if any, the library was linked against.


If you install library in a non standard directory you need to add this path LD_LIBRARY_PATH for Red Hat Linux and SHLIB_PATH for HP-UX

You can add the path using the below command (path has to be added instead of /usr/lib followed by a colon ":")
For Red Hat Linux

# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/local/lib

For HP-UX (Unix)

# export SHLIB_PATH=$SHLIB_PATH:/usr/lib:/usr/local/lib

For making these changes permanent add these path in .bash_profile you must set environment (PATH) variable permanently in Linux
ldconfig man page