How to fix npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found in npm
This error occurs when a native Node.js module requires a newer C++ standard library than your Linux system provides. Solutions include upgrading your system, installing newer GCC, or using containers.
Quick fix
Fixes npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX- Check available GLIBCXX versions
- Install newer GCC (Ubuntu/Debian)
- Install newer GCC (CentOS/RHEL)
- Update libstdc++ directly
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXXnpm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
What this error means
This error indicates that a prebuilt native module requires a newer version of the GNU C++ Standard Library (libstdc++) than what's installed on your system. Similar to glibc errors, this happens when binary packages are compiled on newer systems with newer GCC/G++ versions. The GLIBCXX version corresponds to the GCC version used during compilation. Common GLIBCXX versions: 3.4.21 (GCC 5), 3.4.22 (GCC 6), 3.4.25 (GCC 8), 3.4.28 (GCC 10).
Typical symptoms
- npm install succeeds but module fails at runtime
- Error mentions GLIBCXX_3.4.xx not found
- Occurs on older Linux systems or minimal Docker images
- Affects C++ native modules like sharp, canvas, grpc
- Works on newer systems or after system upgrades
Common causes
- System has old GCC/libstdc++ from outdated Linux distribution
- Using minimal Docker image without updated C++ libraries
- Enterprise system locked to old software versions
- Package binaries built with newer GCC than available
- Mixed environment with incompatible library versions
How to fix "npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found"
See what versions your system supports:
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXXor for CentOS/RHEL:
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXXCompare the highest version to what the error requires.
Install a newer GCC version which includes newer libstdc++:
sudo apt-get update
sudo apt-get install gcc-9 g++-9
# Or use the toolchain PPA for the latest
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-11 g++-11Use devtoolset for newer compilers:
# CentOS 7
sudo yum install centos-release-scl
sudo yum install devtoolset-9
scl enable devtoolset-9 bash
# Then run npm install in this shell
npm installOn some systems, you can update just libstdc++:
# Ubuntu/Debian
sudo apt-get install libstdc++6
# Alpine (if using musl)
apk add libstdc++For containerized apps, switch to a newer base:
# Use newer Debian/Ubuntu base
FROM node:20-bookworm
# Or explicit libstdc++ installation
FROM node:20-slim
RUN apt-get update && apt-get install -y libstdc++6Advanced notes
The GLIBCXX version is determined by the GCC version used to compile the binary:
- GCC 5: GLIBCXX_3.4.21
- GCC 7: GLIBCXX_3.4.24
- GCC 9: GLIBCXX_3.4.26
- GCC 11: GLIBCXX_3.4.29
You can set LD_LIBRARY_PATH to point to a newer libstdc++ without system-wide installation:
export LD_LIBRARY_PATH=/path/to/newer/lib:$LD_LIBRARY_PATHHowever, this can cause other compatibility issues and is not recommended for production.
For packages like sharp or canvas, check if they offer pre-built binaries for your specific platform, or use the --build-from-source flag with your system's compiler.
Frequently asked questions
- What does "npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not" mean?
- This error indicates that a prebuilt native module requires a newer version of the GNU C++ Standard Library (libstdc++) than what's installed on your system. Similar to glibc errors, this happens when binary packages are compiled on newer systems with newer GCC/G++ versions. The GLIBCXX version corresponds to the GCC version used during compilation.
- How do I fix "npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not"?
- This error occurs when a native Node.js module requires a newer C++ standard library than your Linux system provides. Solutions include upgrading your system, installing newer GCC, or using containers.
- What causes "npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not"?
- System has old GCC/libstdc++ from outdated Linux distribution Using minimal Docker image without updated C++ libraries Enterprise system locked to old software versions
- Is the "npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐node-gyp Documentation(Official Docs)
- ๐ฌStack Overflow: libstdc++(Stack Overflow)
- ๐GitHub: node-gyp Issues(GitHub)