Menu

Install C++: Set Up a Compiler on Windows, macOS & Linux

How to install a C++ compiler (GCC, Clang, or MSVC), pick a toolchain for your operating system, and confirm it works from the command line.

This page includes runnable editors - edit, run, and see output instantly.

What You Actually Need: a Compiler

On the previous page you saw that C++ is a compiled language - your source code is turned into native machine code before it runs. To do that on your own machine you install one essential thing: a C++ compiler. The compiler reads your .cpp files, applies the C++ standard library, and produces an executable your CPU runs directly.

You do not need a heavyweight IDE to get started. An IDE is just an editor plus tooling wrapped around the same compiler underneath. Plenty of people write C++ with a plain text editor (or VS Code) and invoke the compiler from a terminal. Install the compiler first; layer an editor on top whenever you like.

You also don't need any of this just to follow along here - the editor blocks on these pages compile and run in the cloud. Set up a local compiler when you want to build and run C++ on your own computer.

Pick a Compiler for Your OS

There are three mainstream C++ compilers, all free and all modern enough for C++17 and C++20:

  • GCC - the GNU Compiler Collection. Its C++ front end is g++. The default on Linux.
  • Clang - the LLVM compiler. Its C++ front end is clang++. The default on macOS.
  • MSVC - Microsoft's compiler (cl.exe), shipped with Visual Studio. The native choice on Windows.

You don't have to overthink this. Use whichever is standard for your platform - the C++ language is the same across all three, and every example in this course compiles on any of them. The differences only matter once you reach advanced, vendor-specific features.

A quick naming gotcha: gcc and g++ are both part of GCC, but for C++ always invoke g++ (not gcc). g++ links the C++ standard library automatically; gcc does not, and you'll get confusing linker errors.

Install on Your Platform

The mechanics differ slightly per OS. Where a package manager exists, prefer it - upgrades become one command.

Windows

The simplest path is the free MinGW-w64 GCC toolchain via the MSYS2 installer. After installing MSYS2, open its terminal and run:

pacman -S mingw-w64-ucrt-x86_64-gcc

That gives you g++. Then add C:\msys64\ucrt64\bin to your PATH so g++ works from any terminal. Alternatively, install Visual Studio (the free Community edition) with the "Desktop development with C++" workload to get the MSVC compiler and an IDE in one go.

macOS

Apple ships Clang through the Command Line Tools. One command installs them:

xcode-select --install

That gives you clang++. If you prefer GCC, install it with Homebrew: brew install gcc.

Linux (Debian/Ubuntu)

sudo apt update
sudo apt install g++

On Fedora/RHEL it's sudo dnf install gcc-c++. These are shell commands, not C++ - they install the compiler system-wide. Installing the build-essential package on Ubuntu pulls in g++ plus make and other build tools in one shot.

Verify It Worked

This is the step people skip and then lose an hour over. Open a new terminal (so it picks up the updated PATH) and ask the compiler its version:

g++ --version

You should see something like:

g++ (Ubuntu 13.2.0-4ubuntu3) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.

On macOS the equivalent is clang++ --version, and on Windows with MSVC it's cl (run from the "Developer Command Prompt"). If you get command not found, the compiler either isn't installed or isn't on your PATH - revisit the install step for your platform and reopen the terminal.

One more useful check: confirm the standard the compiler defaults to. A recent GCC or Clang defaults to C++17 or newer, which is what these pages assume. You can always force a standard explicitly with a flag like -std=c++20, which the next page covers in detail.

A Quick Local Smoke Test

Once g++ --version reports a number, your machine can build C++. The exact same program you'll compile locally also runs right here in the browser, so you can sanity-check the output before you ever touch a terminal:

The __cplusplus macro is a built-in number the compiler defines to tell you which language standard it's using (for example, 201703 means C++17). Every C++ program starts from int main(), and std::cout writes to the console. On your own machine you'd save this as main.cpp, compile it, and run the resulting executable. That two-step build-then-run dance is exactly what the next page is about.

A Note on PATH

The one thing that trips up new installs is PATH - the list of folders your shell searches for programs. If g++ --version runs from any directory, your PATH includes the compiler's folder and you're set. If it only works from the install directory, or not at all, the compiler's bin folder isn't on your PATH yet.

  • On Windows, this is the most common stumbling block: after installing MinGW-w64, you must manually add its bin folder to PATH and open a fresh terminal.
  • On macOS and Linux, the package managers and Xcode tools place the compiler on PATH for you, so this rarely comes up.

If a build tool or editor later can't find your compiler even though g++ --version works in a terminal, a PATH that the GUI app didn't inherit is almost always the cause - restarting the app (or your machine) usually fixes it.

Next: Compiling C++

You now have a working compiler and verified it from the command line. The next page turns that into a real workflow: writing a .cpp file, compiling it with g++ (including the -std and -o flags that control the standard and output name), and running the executable it produces - plus what each step is actually doing under the hood.

Frequently Asked Questions

Do I need an IDE to start writing C++?

No. C++ needs a compiler - an IDE is optional. The compiler (g++, clang++, or MSVC's cl) is what turns your source into a runnable program; an editor like VS Code or an IDE like Visual Studio just makes the workflow nicer. Install the compiler first, add an editor whenever you want.

Which C++ compiler should I install?

Use the standard toolchain for your OS: GCC (g++) on Linux, Clang (clang++) on macOS via Xcode tools, and MSVC or MinGW-w64 on Windows. All three are free and support modern C++17/C++20. Pick one, set it on your PATH, and you can compile every example in this course.

How do I check if a C++ compiler is already installed?

Open a terminal and run g++ --version (or clang++ --version). If you see a version number, a compiler is on your PATH and ready to use. If you get command not found, the compiler is missing or not on your PATH - install the toolchain for your platform below.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED