8.9 /lib, /usr, /opt, /srv: Libraries, User Hierarchy, Add-Ons, Services
Right, let’s talk about where your system actually puts all its stuff. You’ve probably poked around in the root directory (/) and seen a bunch of these cryptic folders. They’re not there by accident (well, mostly). They follow a grand, ancient blueprint called the Filesystem Hierarchy Standard, or FHS. It’s the reason you can, generally, expect to find libraries in /lib and not, say, in /where_did_i_put_that. We’re going to crack open four of the most commonly misunderstood ones: /lib, /usr, /opt, and /srv.
/lib: The Essential Shared Library Stash
Think of /lib as the system’s emergency kit. It contains the essential shared libraries and kernel modules needed to get the most basic utilities and the boot process working. The key word here is essential. If a library in /lib goes missing, you’re probably staring at a system that won’t boot past a grumpy initramfs prompt.
Why is it separate? Historical reasons, mostly. In the dark ages, /usr might have been on a different partition or even a different machine, mounted over the network. The binaries in /bin and /sbin needed their libraries to be available before that fancy /usr partition was mounted. That logic still holds today for your root filesystem. You can see what’s crucial by running:
ls /lib
You’ll see a lot of .so files (shared objects) and a /modules directory for your kernel drivers. A modern twist is /lib64 on 64-bit systems, which exists purely to separate 64-bit libraries from 32-bit ones (which would go in /lib32), avoiding a complete nightmare of filename conflicts.
/usr: It’s Not ‘User’, It’s ‘UNIX System Resources’
This is the biggest misconception. /usr does not stand for ‘user’. It stands for ‘UNIX System Resources’. I know, it’s dumb. Blame the 1970s. This is where the bulk of the software lives after your system is fully booted. It’s the main event.
Its structure is a miniature, more organized version of the root /:
/usr/bin: The primary location for non-essential user commands. Yourpython3,node, andvimlive here. If you type a command, it’s almost certainly here or in/bin./usr/sbin: Non-essential system administration commands. Things likeuseraddorsshdthat a normal user wouldn’t need to run./usr/lib: The vast, sprawling library collection for all the applications in/usr/bin./usr/share: Architecture-independent data. This is genius. Man pages, documentation, timezone info, icons—stuff that doesn’t need to be compiled for a specific CPU architecture goes here. It saves space if you’re sharing this directory across different machines./usr/local: This is your playground. This is where software that you compile yourself, or that your system’s package manager doesn’t provide, should be installed. It has the same bin, lib, share structure. The golden rule: your system’s package manager owns/usr; you own/usr/local. This keeps your custom installs from getting trampled by a system update.
/opt: For Neatly Packaged Third-Party Blobs
Some applications are divas. They demand to be installed in their own directory, with all their binaries, libraries, and resources bundled together in one messy, beautiful, self-contained blob. This is what /opt (for “optional”) is for.
Think of big, proprietary, or complex software: Google Chrome, JetBrains IDEs, MATLAB, or a custom-built enterprise application. They drop themselves into /opt/some-company-name/ and then symlink their main binaries out into /usr/bin (or more commonly, /usr/local/bin) so you can actually launch them.
The advantage? Cleanliness. Uninstalling is often as simple as rm -rf /opt/that-awful-software. The downside? It completely bypasses your system’s shared library model, so each /opt application might bundle its own copies of common libraries, which is a fantastic waste of disk space. You can see who’s camping out here with:
ls /opt
/srv: Put Your Own Server Stuff Here
This one is simple but everyone ignores it. /srv is for “service data”. It’s the designated place where you, the system administrator, are supposed to put the data that your system serves to others.
Are you running a web server? Your website’s files should go in /srv/http or /srv/www. An FTP server? /srv/ftp. A Git repository host? /srv/git.
Why use it? Because it’s the correct, self-documenting choice. If I log into your server and find Apache’s DocumentRoot set to /srv/www, I immediately know that’s data for a service. If I find it in /home/jimmy/public_html, I have to figure out if Jimmy’s account is actually running the server or if this is just a horrifying misconfiguration. /srv separates service data from user data (/home), system data (/etc, /var), and application code (/usr). It’s a best practice that makes your system infinitely more maintainable. If you’re setting up a new service, do the right thing:
sudo mkdir -p /srv/my-new-service
sudo chown www-data:www-data /srv/my-new-service # Or whatever the service user is