How to fix npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found in npm

npmADVANCEDHIGHUpdated Dec 3, 2025ยท 255 views

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
  1. Check available GLIBCXX versions
  2. Install newer GCC (Ubuntu/Debian)
  3. Install newer GCC (CentOS/RHEL)
  4. Update libstdc++ directly
npm โ€” error
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
npm 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

  1. System has old GCC/libstdc++ from outdated Linux distribution
  2. Using minimal Docker image without updated C++ libraries
  3. Enterprise system locked to old software versions
  4. Package binaries built with newer GCC than available
  5. Mixed environment with incompatible library versions

How to fix "npm ERR! Error: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found"

1Check available GLIBCXX versions

See what versions your system supports:

bash
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

or for CentOS/RHEL:

bash
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

Compare the highest version to what the error requires.

2Install newer GCC (Ubuntu/Debian)

Install a newer GCC version which includes newer libstdc++:

bash
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++-11
3Install newer GCC (CentOS/RHEL)

Use devtoolset for newer compilers:

bash
# 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 install
4Update libstdc++ directly

On some systems, you can update just libstdc++:

bash
# Ubuntu/Debian
sudo apt-get install libstdc++6

# Alpine (if using musl)
apk add libstdc++
5Use a newer Docker base image

For containerized apps, switch to a newer base:

dockerfile
# 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++6

Advanced 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:

bash
export LD_LIBRARY_PATH=/path/to/newer/lib:$LD_LIBRARY_PATH

However, 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