Installing a Compiler
Unlike interpreted languages, C++ needs a compiler to translate your source code into a native executable before it can run. There are three major C++ compilers in wide use today, and which one you reach for usually depends on your operating system.
The three major compilers
Compiler | Vendor | Platforms | Typical use |
|---|---|---|---|
GCC (g++) | GNU Project | Linux (default), Windows (via MinGW-w64), macOS | The most widely used free compiler, especially on Linux |
Clang (clang++) | LLVM Project | macOS (default), Linux, Windows | Fast compiles, excellent diagnostics; powers Xcode |
MSVC (cl.exe) | Microsoft | Windows only | Deep Visual Studio integration, strong Windows debugging tools |
Windows
Download MinGW-w64 (for example via the MSYS2 project at msys2.org), then install the g++ package from its package manager.
Add MinGW-w64's
binfolder to your system PATH sog++is available from any terminal.Alternatively, install "Desktop development with C++" from the Visual Studio Installer to get MSVC.
macOS
macOS ships with Clang built in — you just need to install the Xcode Command Line Tools, which include it.
xcode-select --install
Linux
Most Linux distributions can install GCC directly from their package manager. On Debian/Ubuntu-based systems:
sudo apt update sudo apt install build-essential
build-essential pulls in g++, make, and the standard C/C++ headers needed to compile real projects. On Fedora/RHEL-based systems, use sudo dnf groupinstall "Development Tools" instead.
Verifying your installation
Once installed, open a terminal and check the compiler version to confirm it’s on your PATH:
g++ --version
g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc.