Table of Contents#
- Understanding the `GLIBC_2.18' Not Found Error
- Prerequisites
- Step-by-Step Solution: Compiling GLIBC 2.18 from Source
- Configure Redis to Use GLIBC 2.18
- Verify the Fix
- Troubleshooting Common Issues
- Conclusion
- References
Understanding the `GLIBC_2.18' Not Found Error#
What is GLIBC?#
GLIBC is the standard C library for Linux systems, providing core functions for memory management, input/output, and system calls. Most Linux applications (including Redis and its modules) depend on GLIBC to run.
Why CentOS 7 Lacks GLIBC 2.18#
CentOS 7 is built on a stable, long-term support (LTS) model, prioritizing compatibility over cutting-edge updates. Its default repositories include GLIBC 2.17, released in 2012. Newer Redis modules, however, are often compiled on systems with newer GLIBC versions (e.g., Ubuntu 18.04+ uses GLIBC 2.27), leading to version mismatches.
The Error Message#
When you try to load a module compiled for GLIBC 2.18+ on CentOS 7, Redis will fail with an error like:
redis-server: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /path/to/your/module.so) This means the module expects GLIBC 2.18, but your system only has 2.17.
Prerequisites#
Before proceeding, ensure you have:
- A CentOS 7 server with
sudoaccess. - At least 2 GB of RAM (compiling GLIBC is memory-intensive).
- 10 GB of free disk space (for source files and compilation).
- Internet access to download dependencies and GLIBC source code.
- Basic familiarity with the Linux command line.
Critical Warning: Upgrading the system-wide GLIBC can break CentOS 7, as core system tools (e.g., ls, cp) depend on GLIBC 2.17. We will install GLIBC 2.18 to a non-system directory (e.g., /opt/glibc-2.18) to avoid overwriting the system library.
Step-by-Step Solution: Compiling GLIBC 2.18 from Source#
3.1 Update System Dependencies#
First, install tools required to compile GLIBC:
sudo yum update -y
sudo yum install -y gcc make bison flex perl-devel texinfo glibc-devel.i686 libgcc.i686 3.2 Download GLIBC 2.18 Source Code#
GLIBC source code is hosted on the GNU FTP server. Use wget to download version 2.18:
cd /tmp
wget https://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz Verify the download with a checksum (optional but recommended):
# Download the checksum file
wget https://ftp.gnu.org/gnu/glibc/glibc-2.18.tar.gz.sig
# Verify (requires GPG; skip if not installed)
gpg --verify glibc-2.18.tar.gz.sig glibc-2.18.tar.gz 3.3 Prepare for Compilation#
Extract the source code and create an out-of-tree build directory (recommended for clean compilation):
tar -xzf glibc-2.18.tar.gz
cd glibc-2.18
mkdir build && cd build # Build in a subdirectory to avoid polluting source files 3.4 Configure and Compile GLIBC 2.18#
Configure the build to install GLIBC 2.18 to /opt/glibc-2.18 (a non-system path) and enable 64-bit support:
../configure \
--prefix=/opt/glibc-2.18 \
--libdir=/opt/glibc-2.18/lib64 \
--enable-multi-arch \
--enable-static-nss \
--disable-werror --prefix=/opt/glibc-2.18: Installs GLIBC to a custom directory (safe for CentOS 7).--libdir=/opt/glibc-2.18/lib64: Ensures 64-bit libraries are placed inlib64(required for CentOS 7).--disable-werror: Prevents compilation failures due to non-critical warnings.
Compile GLIBC (this takes 10–30 minutes, depending on your server’s CPU):
make -j $(nproc) # Use all CPU cores for faster compilation Note: If compilation fails with errors like undefined reference to '__tls_get_addr', ensure you installed glibc-devel.i686 and libgcc.i686 in Step 3.1.
3.5 Install GLIBC 2.18 to a Non-System Directory#
Install the compiled GLIBC to /opt/glibc-2.18:
sudo make install Verify the installation:
ls -l /opt/glibc-2.18/lib64/libc.so.6 You should see a symlink to libc-2.18.so.
Configure Redis to Use GLIBC 2.18#
Now, tell Redis to use the newly installed GLIBC 2.18 instead of the system’s GLIBC 2.17. We’ll use the LD_LIBRARY_PATH environment variable to prioritize the custom GLIBC directory.
For Manual Redis Starts#
If you start Redis manually (e.g., redis-server), prepend LD_LIBRARY_PATH to the command:
LD_LIBRARY_PATH=/opt/glibc-2.18/lib64 redis-server /etc/redis.conf For Systemd-Managed Redis (Recommended)#
Most production Redis instances use systemd. To permanently set LD_LIBRARY_PATH for the Redis service:
-
Create an override file for the Redis systemd service:
sudo systemctl edit redis -
Add the following lines to the override file (replace
/opt/glibc-2.18/lib64with your GLIBC path if different):[Service] Environment="LD_LIBRARY_PATH=/opt/glibc-2.18/lib64" -
Save and exit the editor (Ctrl+O, Enter, Ctrl+X in nano).
-
Restart Redis to apply the change:
sudo systemctl restart redis
Verify the Fix#
Check GLIBC Version for the Redis Module#
Use ldd (list dynamic dependencies) to confirm the Redis module now finds GLIBC 2.18:
LD_LIBRARY_PATH=/opt/glibc-2.18/lib64 ldd /path/to/your/module.so Look for a line like:
libc.so.6 => /opt/glibc-2.18/lib64/libc.so.6 (0x00007f...). If GLIBC_2.18 is no longer marked as "not found," the fix works!
Test Module Loading in Redis#
Connect to Redis and load the module:
redis-cli
127.0.0.1:6379> MODULE LOAD /path/to/your/module.so
OK If you see OK, the module loaded successfully.
Troubleshooting Common Issues#
"Permission Denied" When Accessing /opt/glibc-2.18/lib64#
Ensure the Redis user (e.g., redis) has read access to the GLIBC directory:
sudo chmod -R 755 /opt/glibc-2.18 Compilation Fails with "insufficient memory"#
GLIBC compilation requires ~2 GB of RAM. If you hit this error:
- Add swap space temporarily:
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile
Redis Fails to Start After Systemd Configuration#
Check the Redis logs for errors:
sudo journalctl -u redis If logs show error while loading shared libraries: libc.so.6: cannot open shared object file, ensure LD_LIBRARY_PATH is set correctly in the systemd override.
Conclusion#
The GLIBC_2.18' not found error on CentOS 7 is caused by a mismatch between the system’s older GLIBC (2.17) and modern Redis modules compiled for newer GLIBC versions. By compiling GLIBC 2.18 from source and installing it to a non-system directory, you can safely resolve the compatibility issue without breaking your CentOS 7 system.
For long-term stability, consider migrating to a newer OS (e.g., CentOS Stream 8/9, Rocky Linux, or Ubuntu 20.04+) if possible, as these ship with newer GLIBC versions by default.