Difference Between /lib and /lib64 in Linux
In the Linux operating system, both /lib and
/lib64 are system directories designated for storing
critical shared libraries and kernel modules required for system booting
and running commands in the root filesystem. The primary distinction
between the two lies in system processor architecture and how a
distribution handles multilib (the capability to run both 32-bit and
64-bit applications on the same operating system). While
/lib historically housed 32-bit libraries,
/lib64 was introduced to house 64-bit libraries, though the
exact implementation varies significantly across different Linux
distributions.
Processor Architecture and Library Separation
Shared libraries are compiled machine code loaded by executables at runtime. Because a 64-bit executable cannot link against a 32-bit library and vice versa, systems capable of running both binary formats need distinct locations to store their respective libraries without naming collisions.
- /lib: Historically, this directory held all
essential shared libraries for 32-bit systems. On many 64-bit
distributions that support multilib,
/libcontinues to host 32-bit libraries to maintain backward compatibility. - /lib64: Introduced alongside 64-bit x86-64
architectures, this directory holds essential 64-bit shared libraries,
including the dynamic linker/loader
(
ld-linux-x86-64.so).
Differences Across Linux Distributions
The relationship between /lib and /lib64
depends on how a specific Linux distribution implements the Filesystem
Hierarchy Standard (FHS):
Red Hat, Fedora, CentOS, and openSUSE
These distributions strictly follow the multilib separation paradigm:
/libcontains 32-bit shared object files (.so)./lib64contains 64-bit shared object files.
If you compile a 64-bit application on these distributions, the
dynamic linker looks inside /lib64 (and
/usr/lib64) by default.
Debian and Ubuntu
Debian and its derivatives use a "Multiarch" architecture
specification rather than the multilib directory structure. Instead of
splitting libraries into /lib and /lib64,
Debian uses architecture-specific subdirectories under /lib
and /usr/lib:
/lib/x86_64-linux-gnu/for 64-bit x86 libraries./lib/i386-linux-gnu/for 32-bit x86 libraries.
On these systems, /lib64 typically exists solely to
maintain compatibility with the Linux Standard Base (LSB), often
containing only the dynamic linker symlink pointing into
/lib.
Arch
Linux and Modern Systemd Distributions (Merged /usr)
Modern distributions often implement the "UsrMerge" specification,
where root system directories are merged into /usr:
/libis a symbolic link pointing to/usr/lib./lib64is a symbolic link pointing to/usr/lib64(or directly to/usr/libon pure 64-bit setups).
The Dynamic Linker and Configuration
The operating system determines which library path to use when
launching a binary via the dynamic linker (ld.so). The
dynamic linker references paths listed in /etc/ld.so.conf
and pre-indexed in the /etc/ld.so.cache binary
database.
You can inspect which directory your dynamic binaries use by
inspecting the binary with the ldd command:
ldd /bin/lsOn a standard 64-bit multilib system, the output will reference
libraries located in /lib64 or /usr/lib64.