To install a C++ compiler, pick the toolchain for your operating system: MSVC (Visual Studio Build Tools) or MinGW-w64 on Windows, GCC through your package manager on Linux, and Clang from the Xcode Command Line Tools on macOS. Once the compiler is on your PATH, you can build any C++ file from a terminal.
This guide shows the install steps for each system, how to check that the compiler works, and how to choose between the common options. Every command below assumes a recent compiler that supports C++17 or newer.
A C++ compiler translates your source code into machine code that the processor can run. The three compilers you will meet most often are:
| Compiler | Command | Typical platform | Notes |
|---|---|---|---|
| GCC | g++ | Linux, Windows (MinGW-w64, MSYS2) | Free, very widely used |
| Clang | clang++ | macOS, Linux, Windows | Default on macOS, clear error messages |
| MSVC | cl | Windows | Ships with Visual Studio and Build Tools |
All three support modern standards. If you have no strong preference, use the default for your system: MSVC on Windows, GCC on Linux and Clang on macOS. You can install more than one and switch later.
You have two good options on Windows.
cl is available.To check the compiler, run:
You should see the Microsoft C/C++ compiler banner with its version number. The plain Command Prompt or PowerShell will not find cl until you use the developer prompt.
C:\msys64\ucrt64\bin to your Windows PATH so that g++ works from any terminal.Check the result with g++ --version. This option gives you the same GCC that Linux users have, which is handy when you follow tutorials written for Linux.
On Linux you install the compiler with your distribution's package manager. Use the command that matches your system.
On Debian-based systems, build-essential installs g++, gcc, make and the standard headers in one step. To use Clang instead, install the clang package with the same package manager.
macOS ships Clang through Apple's Command Line Tools. Open Terminal and run:
A dialog asks you to confirm the download. After it finishes, clang++ is available, and g++ is a name that points to the same Apple Clang compiler, not to GNU GCC. You do not need the full Xcode application to compile command-line programs. If you want real GCC, install it with Homebrew (brew install gcc) and call it as g++-14 or the version number Homebrew installs.
Verify the installation on any system by printing the version:
Then compile a tiny program. Save this as check.cpp:
Compile and run it:
On Windows with MSVC, use cl /EHsc /std:c++20 check.cpp and then run check.exe. If the compiler runs and prints the message, your setup is ready.
g++ is not recognised: the compiler folder is missing from PATH. Reopen the terminal after changing PATH, because existing windows keep the old value.cl is not recognised on Windows: you opened a normal prompt instead of the Developer Command Prompt.build-essential (or the equivalent) rather than only gcc.-std=c++20. Update your system or install a newer toolchain.No. A text editor and a compiler in a terminal are enough. IDEs such as Visual Studio, CLion or VS Code add debugging and code navigation, but they still call a compiler underneath.
Use the default for your system. GCC and Clang give readable error messages, and MSVC integrates well with Visual Studio. The language you learn is the same.
Both belong to GCC. The g++ command treats files as C++ and links the C++ standard library automatically, while gcc treats .c files as C.
Yes. They live side by side, and you choose one by typing its command. Testing code with two compilers is a good way to catch non-portable code.
Install MSVC or MSYS2 GCC on Windows, build-essential on Linux and the Command Line Tools on macOS. Confirm the setup with --version and by compiling a small program with -std=c++20. With a working compiler, you are ready to write and run your first C++ program.