CppInstalling a Compiler

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
You have two solid options on Windows: install MinGW-w64 for a lightweight g++ toolchain, or install the Visual Studio Build Tools for Microsoft’s MSVC compiler. MinGW-w64 is the simpler choice if you want the same GCC-based workflow used on Linux and in most tutorials.
  • 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 bin folder to your system PATH so g++ 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.

Bash
xcode-select --install
Linux

Most Linux distributions can install GCC directly from their package manager. On Debian/Ubuntu-based systems:

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

Bash
g++ --version
g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
Specify a C++ standard version
Compilers default to different (sometimes old) C++ standards depending on their release. Always be explicit with the `-std` flag, for example `g++ -std=c++20 file.cpp -o program`, so your code compiles the same way everywhere.