This error occurs when node-gyp can't find the G++ C++ compiler. Native npm modules with C++ code require g++ for compilation, and this fails if it's not installed.
The "not found: g++" error means node-gyp needs to compile C++ code but can't find the G++ compiler. While `cc` or `gcc` handles C code, `g++` is specifically needed for C++ code. Many npm packages with native modules are written in C++ rather than C. Packages like bcrypt, sqlite3, canvas, and leveldown contain C++ code that requires g++ for compilation. This error is essentially the same as the "cc not found" error but specifically for the C++ compiler.
Install g++ with the build-essential package:
sudo apt-get update
sudo apt-get install -y build-essential
# Or install g++ specifically
sudo apt-get install -y g++
# Verify
g++ --version# RHEL/CentOS
sudo yum install gcc-c++
# Fedora
sudo dnf install gcc-c++
# Or install full development tools
sudo yum groupinstall "Development Tools"Install Xcode Command Line Tools which includes clang++:
xcode-select --installmacOS uses clang/clang++ instead of gcc/g++, but node-gyp handles this automatically.
Install Visual Studio with C++ support:
# Option 1: windows-build-tools (run as Admin)
npm install --global --production windows-build-tools
# Option 2: Install Visual Studio Community
# Select "Desktop development with C++" workloadAdd to your Dockerfile:
Debian/Ubuntu based:
RUN apt-get update && apt-get install -y \
python3 make g++ \
&& rm -rf /var/lib/apt/lists/*Alpine based:
RUN apk add --no-cache python3 make g++After installing g++:
npm cache clean --force
npm installgcc vs g++: gcc is the C compiler, g++ is the C++ compiler. Most native Node.js modules use C++, so both are typically needed. The build-essential package on Debian/Ubuntu includes both.
Compiler alternatives: On macOS, clang++ serves the same purpose as g++. node-gyp automatically uses the appropriate compiler for your platform.
Version compatibility: Very old or very new g++ versions might cause issues. Most packages work with g++ 4.9 through 13. If you have version issues:
# Install specific version
sudo apt-get install g++-11
# Set as default
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error