How to fix npm ERR! gyp ERR! stack Error: not found: g++ in npm
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.
Quick fix
Fixes npm ERR! gyp ERR! stack Error: not found: g++
sudo apt-get update
sudo apt-get install -y build-essential
# Or install g++ specifically
sudo apt-get install -y g++
# Verify
g++ --version- Install g++ on Linux (Debian/Ubuntu)
- Install g++ on Linux (RHEL/CentOS/Fedora)
- Install on macOS
- Install on Windows
sudo apt-get updatesudo apt-get install -y build-essential# Or install g++ specificallysudo apt-get install -y g++# Verifyg++ --versionnpm ERR! gyp ERR! stack Error: not found: g++
What this error means
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.
Typical symptoms
- npm install fails with 'gyp ERR! not found: g++'
- Error when installing packages with C++ native modules
- gcc works but g++ is missing
- Happens after installing only gcc without g++
Common causes
- G++ compiler not installed
- Only gcc installed without g++ (incomplete toolchain)
- Build tools not in system PATH
- Minimal Docker/container image
- Fresh system without development packages
How to fix "npm ERR! gyp ERR! stack Error: not found: g++"
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 installAdvanced notes
gcc 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 100Frequently asked questions
- What does "npm ERR! gyp ERR! stack Error: not found: g++" mean?
- 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.
- How do I fix "npm ERR! gyp ERR! stack Error: not found: g++"?
- 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.
- What causes "npm ERR! gyp ERR! stack Error: not found: g++"?
- G++ compiler not installed Only gcc installed without g++ (incomplete toolchain) Build tools not in system PATH
- Is the "npm ERR! gyp ERR! stack Error: not found: g++" 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
- ๐GitHub: node-gyp(GitHub)
- ๐Docs: node-gyp guide(Official Docs)
- ๐ฌSO: g++ compiler issues(Stack Overflow)