Search Authority

Fix "g++ Command Not Found": Easy Solutions & Optimization Tips

If you are developing on Linux or working with command line tools on macOS, seeing the error g++ command not found can block your build and slow down your workflow. This usually...

Mara Ellison
Fix "g++ Command Not Found": Easy Solutions & Optimization Tips

If you are developing on Linux or working with command line tools on macOS, seeing the error g++ command not found can block your build and slow down your workflow. This usually means the GNU C++ compiler is not installed or not available in your shell PATH.

Understanding how this error occurs and how to resolve it helps you avoid wasted time and keeps your development environment reliable. The following sections cover diagnosis, installation, PATH configuration, and common troubleshooting steps.

Platform Package name Quick install command Compiler binary location after install
Ubuntu / Debian g++ sudo apt update && sudo apt install g++ /usr/bin/g++
CentOS / RHEL gcc-c++ sudo dnf install gcc-c++ /usr/bin/g++
Fedora gcc-c++ sudo dnf install gcc-c++ /usr/bin/g++
macOS with Homebrew gcc brew install gcc /usr/local/bin/g++-13 (versioned)
Windows WSL g++ sudo apt install g++ /usr/bin/g++

Install GNU C++ Compiler Correctly

Installing the correct package for your distribution is the most direct fix for g++ command not found. On Debian based systems, the g++ package provides the GNU C++ compiler. On Red Hat based systems, the package is usually called gcc-c++.

Using the native package manager ensures that the compiler is placed in a standard system directory and that required dependencies are configured. After installation, verify the setup by checking the version output.

Verify PATH and Shell Environment

Check if g++ binary exists

Run locate or find to see whether the g++ binary is present on the system. If locate database is outdated, updatedb or sudo updatedb may be required before using locate.

Check PATH directories

Your shell PATH must include the directory where g++ is installed, commonly /usr/bin. If you installed GCC via Homebrew on macOS, the binaries might be under a versioned path like /usr/local/opt/gcc/libexec/gcc, so adjust PATH accordingly.

Diagnose Common Misconfigurations

Sometimes g++ is installed but not linked into a directory listed in PATH, which triggers g++ command not found even though the compiler exists. Review your PATH using echo $PATH and compare it to the actual location of the binary with which g++ or type g++ when the error appears.

On macOS, installing gcc via brew may create versioned symlinks such as g++-13. You can create a generic g++ symlink or add an alias in your shell configuration to point g++ to the appropriate versioned binary.

Final Recommendations for Reliable Builds

  • Install g++ using the official package manager for your platform to ensure correct paths and dependencies.
  • Verify that the directory containing g++ is included in your shell PATH before running build scripts.
  • On macOS with Homebrew, create or use the versioned symlink for g++ and confirm it points to the correct compiler version.
  • Refresh the locate database with updatedb if you rely on locate or other file based discovery tools.
  • Use type or which to troubleshoot PATH issues and confirm the exact binary being invoked during builds.

FAQ

Reader questions

Why do I still see g++ command not found after installing gcc on macOS with Homebrew?

Homebrew installs versioned binaries like g++-13; you need to add a symlink such as ln -s /usr/local/bin/g++-13 /usr/local/bin/g++ or ensure the versioned bin directory is in your PATH.

How can I check which g++ binary my shell is trying to use?

Use type g++ or which g++ to see the path of the binary that the shell would execute, and compare it with the output of echo $PATH.

What should I do if updatedb does not find g++ with locate?

Run sudo updatedb to refresh the locate database, then use locate g++ to search for the binary and confirm its location.

Can I fix g++ command not found by editing my shell profile?

Yes, if the binary exists but is not in PATH, add its directory to PATH in ~/.bashrc, ~/.zshrc, or the appropriate shell configuration file, then source the file or restart the terminal.

Related Reading

More pages in this topic cluster.

Who Designed the Nike Logo? The Story Behind the Swoosh

The Nike swoosh is one of the most recognizable symbols in the world, but few people know the story behind its creation. This piece explores who designed the Nike logo, why it h...

Read next
What is the World's Hottest Pepper? 🌶️🔥

When people ask about the world's hottest pepper, they usually mean the variety that currently holds the Guinness World Record and pushes the boundaries of capsaicin heat. Peppe...

Read next
Jon Huertas in This Is Us:角色, 出演时期与剧情影响详解

Jon Huertas 在《这就是我们》中饰演成年 Kevin Pearson,这一角色从2016年首播持续至2022年最终季,构成了剧集核心家庭叙事的重要组成部�...

Read next