How to fix npm ERR! gyp ERR! stack Error: not found: g++ in npm

npmBEGINNERHIGHUpdated Dec 5, 2025ยท 110 views

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
  1. Install g++ on Linux (Debian/Ubuntu)
  2. Install g++ on Linux (RHEL/CentOS/Fedora)
  3. Install on macOS
  4. Install on Windows
npm โ€” error
sudo apt-get update
sudo apt-get install -y build-essential
# Or install g++ specifically
sudo apt-get install -y g++
# Verify
g++ --version
npm 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

  1. G++ compiler not installed
  2. Only gcc installed without g++ (incomplete toolchain)
  3. Build tools not in system PATH
  4. Minimal Docker/container image
  5. Fresh system without development packages

How to fix "npm ERR! gyp ERR! stack Error: not found: g++"

1Install g++ on Linux (Debian/Ubuntu)

Install g++ with the build-essential package:

bash
sudo apt-get update
sudo apt-get install -y build-essential

# Or install g++ specifically
sudo apt-get install -y g++

# Verify
g++ --version
2Install g++ on Linux (RHEL/CentOS/Fedora)
bash
# RHEL/CentOS
sudo yum install gcc-c++

# Fedora
sudo dnf install gcc-c++

# Or install full development tools
sudo yum groupinstall "Development Tools"
3Install on macOS

Install Xcode Command Line Tools which includes clang++:

bash
xcode-select --install

macOS uses clang/clang++ instead of gcc/g++, but node-gyp handles this automatically.

4Install on Windows

Install Visual Studio with C++ support:

powershell
# 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++" workload
5Install in Docker

Add to your Dockerfile:

Debian/Ubuntu based:

dockerfile
RUN apt-get update && apt-get install -y \
    python3 make g++ \
    && rm -rf /var/lib/apt/lists/*

Alpine based:

dockerfile
RUN apk add --no-cache python3 make g++
6Retry the installation

After installing g++:

bash
npm cache clean --force
npm install

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

bash
# Install specific version
sudo apt-get install g++-11

# Set as default
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100

Frequently 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