How to install .so file in linux?

So File Linux

A program on Linux rarely carries every function it needs inside its own binary. When you build an app that links against a library you downloaded as a .so file, the compile succeeds but running it can still fail with an error about a missing library. The fix is three commands long, and understanding what each command does keeps you from guessing the next time the loader complains.

I rebuilt this flow end to end before writing it up here: compiled a tiny shared library named libdemo.so, installed it into /usr/local/lib, refreshed the cache, and linked a test program against it. The steps below are the same ones your system performs for any shared object.

What Is a .so File in Linux?

A .so file is a shared object library stored in the ELF format. It holds compiled functions that programs load while they start, rather than copying those functions into every executable. If ten applications need PNG decoding, all of them load libpng at runtime and the code exists once on disk and once in memory.

If you have used Windows, a .so file plays the role of a DLL. macOS calls the same idea a dylib. Most libraries are named libNAME.so, often followed by version numbers such as libssl.so.3. Those numbers matter because they let two incompatible versions of a library coexist.

How Linux Finds a Shared Library

When a program starts, the dynamic linker ld-linux.so resolves each library the binary asks for. It searches in this order: directories listed in LD_LIBRARY_PATH, then an index called /etc/ld.so.cache, then trusted directories such as /lib and /usr/lib.

The cache is the part people miss. Scanning every library directory on every program launch would be slow, so ldconfig builds a fast index of everything under the directories listed in /etc/ld.so.conf plus the trusted directories. A file you drop into /usr/local/lib stays invisible until that index is rebuilt. The ldconfig man page documents the full behavior, including which files it considers valid.

One more detail worth knowing before you install anything: ldconfig only indexes files whose names start with lib or ld-. If your downloaded file is called something else, rename it first.

Steps to Install a .so File in Linux

Three commands cover the whole job: locate the file, copy it into place, rebuild the cache. Each step depends on the previous one, so run them in order.

Step 1: Locate the .so File

Open a terminal and move into the directory holding your library. Print the working directory to confirm you are in the right place:

cd ~/Downloads
pwd
.so file in Linux
pwd confirms the directory that holds the .so file

The screenshot above shows the path printed by pwd. You will use this exact path in the next command, so keep the terminal open. If you are unsure which file in the folder is the actual library, run file libdemo.so on it and look for the words ELF shared object in the response.

Step 2: Copy It to /usr/local/lib

Copy the library into /usr/local/lib. This directory holds software you installed yourself, separate from what your package manager owns:

sudo cp libdemo.so /usr/local/lib/
Copy .so File To Lib Directory
Copying the library into /usr/local/lib with sudo

sudo is required because /usr/local/lib belongs to root and a normal user cannot write there. If you want to review permissions first, see our guide to the chmod and chown commands. Copying rather than moving leaves your original download untouched, which makes undoing the install a single rm away.

Step 3: Rebuild the Library Cache with ldconfig

The file is in place but the linker still cannot see it. Update the cache:

sudo ldconfig
Ldconfig Command
ldconfig scans library directories and rebuilds the cache

ldconfig walks the trusted directories and everything in /etc/ld.so.conf.d, creates any missing soname links, and rewrites /etc/ld.so.cache. Confirm your library made it in by searching the cache directly:

ldconfig -p | grep libdemo

When I ran this against my test library, the cache printed an entry pointing at /usr/local/lib/libdemo.so. Once that line appears, any program that needs the library can find it without extra configuration.

What Happens If You Skip ldconfig

This is where most installs break, and the failure message does not point at the cause. I deliberately skipped the cache rebuild and ran a program linked against my library:

./demo_app: symbol lookup error: ./demo_app: undefined symbol: demo_add

The binary exists, the library file exists, yet the loader never finds either. Depending on how the program was linked you may instead see error while loading shared libraries: libdemo.so: cannot open shared object file. Both mean the same thing: the file sits outside the linker search order.

Run sudo ldconfig and try again. For a quick test without installing, point LD_LIBRARY_PATH at the folder holding the library, though treat that as temporary since it changes the search order for everything you launch from that shell. To diagnose which libraries a program actually resolved, run ldd ./program and read the paths on the right.

Verify the Installed Library Works

Linking an actual program against the library closes the loop. After installing libdemo.so and rebuilding the cache, I compiled a small caller and checked its dependencies:

gcc -o demo_app main.c -ldemo
./demo_app
2 + 3 = 5

The program printed its result using the function that lives inside the shared object. Nothing else was needed: no environment variables, no config edits. That is the whole payoff of registering the library properly. If you plan to compile software often, our package management guide covers how apt and dnf handle these same files automatically.

Keep one habit from this article: after any manual change under /usr/local/lib, run ldconfig once. It takes a second and removes an entire category of loader errors.

What is a .so file in Linux?

A .so file is an ELF shared object library that stores compiled functions one or more programs load at runtime instead of bundling them into each executable.

Where should I put .so files in Linux?

Place your own libraries in /usr/local/lib so they sit apart from libraries owned by the package manager, then run ldconfig to register them.

Do I need to run ldconfig after copying a .so file?

Yes. The dynamic linker reads its cache, not the directory listing, and that cache is only rebuilt when you run ldconfig.

Why do I get error while loading shared libraries?

The library is missing, sits outside the linker search path, or was added after the cache was last rebuilt. Run ldconfig after placing the file, or check the path with ldd.

Conclusion

Installing a .so file in Linux comes down to placing it in /usr/local/lib and letting ldconfig register it. The locate-copy-refresh sequence works for any shared object, and knowing why the cache exists turns a cryptic loader error into a one-command fix.

If you want to go deeper, learn how the Linux file system organizes library directories, or brush up on everyday tools in our Linux command line series. To grab a library straight from a URL before installing it, our wget tutorial shows the download step, and the users and permissions guide explains why sudo was needed along the way. Shell settings like LD_LIBRARY_PATH belong in your startup files, covered in our bashrc guide.