g++: command not found
g++: command not found
DodaTech
2 min read
The g++: command not found error means the GNU C++ Compiler is missing. It happens when trying to compile C++ code but the compiler is not installed.
What It Means
The shell cannot find the g++ binary. Unlike gcc (the C compiler), g++ is often part of a separate package even on systems where GCC is installed.
Why It Happens
g++is not installed (common on minimal Docker images and fresh systems)- Only
gccwas installed, which handles C but not C++ - The
build-essentialmeta-package was not installed (Debian/Ubuntu) - PATH does not include the directory where
g++is located
How to Fix It
Step 1: Install g++ on Debian/Ubuntu
The recommended approach installs the full build toolchain:
sudo apt update
sudo apt install build-essentialThis installs g++, gcc, make, and other development tools together. Alternatively, install only g++:
sudo apt install g++Step 2: Install g++ on Fedora/RHEL
sudo dnf install gcc-c++Step 3: Install g++ on macOS
Install Xcode Command Line Tools:
xcode-select --installOn macOS, g++ is often mapped to clang++. The command still works the same way.
Step 4: Install g++ on Windows
Use MinGW-w64 or MSYS2:
# With Chocolatey
choco install mingw
# Or with MSYS2
pacman -S mingw-w64-x86_64-gccStep 5: Test the installation
Create a simple C++ program:
// hello.cpp
#include <iostream>
int main() {
std::cout << "Hello, g++!" << std::endl;
return 0;
}g++ hello.cpp -o hello
./helloExpected output:
Hello, g++! Previous
FATAL: Unable to parse /etc/ansible/hosts as an inventory source
Next
Global symbol requires explicit package name
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro