Step-by-Step Guide – Installing C++ on Windows, Mac, and Linux

9/12/2025
All Articles

diagram of Installing C++ cplus on Windows, Mac, Linux

Step-by-Step Guide – Installing C++ on Windows, Mac, and Linux

Step-by-Step Guide – Installing C++ on Windows, Mac, and Linux

Introduction

To write and run C++ programs, you need a C++ compiler installed on your computer. The most commonly used compiler is GCC (GNU Compiler Collection), which is cross-platform and free. This guide will walk you through installing C++ on Windows, macOS, and Linux.


Install C++ on Windows

Step 1: Install MinGW (GCC for Windows)

  1. Visit the MinGW official website.

  2. Download the mingw-get-setup.exe installer.

  3. Run the installer and choose mingw32-gcc-g++ package.

  4. Complete installation.

Step 2: Add MinGW to System Path

  1. Go to Control Panel → System → Advanced System Settings.

  2. Click Environment Variables.

  3. Under System variables, edit Path and add:
    C:\MinGW\bin

  4. Click OK to save.

Step 3: Verify Installation

Open Command Prompt and type:

g++ --version

If installed correctly, it will display the GCC version.


Install C++ on macOS

Step 1: Install Xcode Command Line Tools

  1. Open Terminal.

  2. Run:

xcode-select --install
  1. Accept the license agreement and wait for installation.

Step 2: Verify Installation

Check GCC version by running:

g++ --version

This confirms that the C++ compiler is installed.


Install C++ on Linux

Step 1: Update Package Manager

Open the terminal and update the package list:

sudo apt update       # For Ubuntu/Debian
sudo dnf update       # For Fedora

Step 2: Install GCC Compiler

sudo apt install build-essential       # Ubuntu/Debian
sudo dnf install gcc-c++               # Fedora
sudo pacman -S gcc                     # Arch Linux

Step 3: Verify Installation

g++ --version

This should show the installed version of GCC.


Test Your C++ Setup

Once installed, create a simple C++ file named hello.cpp:

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!";
    return 0;
}

Compile and run it:

g++ hello.cpp -o hello
./hello

You should see: Hello, World!


Conclusion

With a compiler installed on your system, you are now ready to write and execute C++ programs. This setup is the first step towards mastering C++ programming on Windows, macOS, and Linux.


Step-by-step guide - Installing C++ on Windows / macOS / Linux

Meta Description:
A clear, copy‑paste step‑by‑step guide to install a C++ toolchain on Windows, macOS, and major Linux distributions. Includes verification, a sample program, and troubleshooting tips.

Meta Keywords:
install C++, install g++, install MSVC, MSYS2, Xcode command line tools, build-essential, WSL


Quick overview

C++ development requires a compiler (GCC/Clang/MSVC), optional build tools, and optionally an IDE or editor. Below are simple, tested steps for each platform.


Windows

Option A — Visual Studio (MSVC) — recommended for Windows developers

  1. Download the Visual Studio Community installer from the official site (choose "Desktop development with C++" workload).

  2. Run the installer and select the "Desktop development with C++" workload. You can also add optional components such as CMake, Clang tools, and Windows SDKs.

  3. After install, open Developer Command Prompt for Visual Studio from the Start menu.

  4. Verify MSVC is available:

cl

You should see the MSVC version and usage help. To compile:

cl /EHsc hello.cpp

Option B — MinGW-w64 (GCC) via MSYS2 — lightweight, compatible with many Unix-style workflows

  1. Download and install MSYS2 from https://www.msys2.org.

  2. Open the MSYS2 MinGW 64-bit shell and update packages:

pacman -Syu
# close and re-open the MSYS2 shell when prompted
pacman -Su
  1. Install the mingw-w64 toolchain (64-bit):

pacman -S --needed base-devel mingw-w64-x86_64-toolchain
  1. In the MSYS2 MinGW 64-bit shell, verify:

g++ --version
  1. Compile:

g++ -std=c++17 hello.cpp -o hello.exe
./hello.exe

Option C — WSL (Windows Subsystem for Linux)

  1. Enable WSL and install a Linux distro (Windows 10/11):

wsl --install -d ubuntu
  1. Open the installed distro and install build tools:

sudo apt update && sudo apt install build-essential gdb -y
  1. Verify and compile as on Linux (see below).


macOS

Option A — Xcode Command Line Tools (Clang)

  1. Open Terminal and run:

xcode-select --install
  1. Verify compiler:

clang --version
# or
g++ --version  # this may show Apple clang
  1. Compile:

clang++ -std=c++17 hello.cpp -o hello
./hello

Option B — Homebrew + GCC (optional if you prefer GNU toolchain)

  1. Install Homebrew (if not already installed):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install GCC:

brew install gcc
  1. Homebrew GCC installs versioned binaries like g++-13 — verify:

g++-13 --version
  1. Compile with the GNU compiler:

g++-13 -std=c++17 hello.cpp -o hello
./hello

Linux

(Commands below assume a terminal with sudo privileges.)

Debian / Ubuntu / Linux Mint

sudo apt update
sudo apt install build-essential gdb -y

Verify:

g++ --version

Compile:

g++ -std=c++17 hello.cpp -o hello
./hello

Fedora / Red Hat / CentOS (dnf)

sudo dnf groupinstall "Development Tools" -y
sudo dnf install gcc-c++ gdb -y

Arch Linux

sudo pacman -Syu
sudo pacman -S base-devel gcc gdb

Sample Hello World program (copy & paste)

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Compile with a modern standard and warnings enabled:

# Using GCC/Clang
g++ -std=c++17 -Wall -Wextra -O2 hello.cpp -o hello
./hello

# MSVC (in Developer Command Prompt)
cl /EHsc /std:c++17 hello.cpp

Optional: Install an IDE or code editor

  • Visual Studio (Windows) — full-featured IDE with MSVC.

  • CLion (cross-platform, commercial) — excellent CMake support.

  • Visual Studio Code + C/C++ extension (free) — lightweight and configurable.

  • Eclipse CDT, Code::Blocks — other cross-platform options.


Troubleshooting & Tips

  • "g++: command not found" — ensure you installed build tools and that the toolchain bin folder is in PATH (Windows MinGW/MSYS2).

  • MSVC not recognized — use the "Developer Command Prompt for Visual Studio" which sets environment variables.

  • Permissions / Antivirus — Windows Defender or third‑party AV may block executables created during testing; allow the folder or disable temporarily.

  • Using the right toolchain on macOSg++ often points to Apple Clang; use g++-<version> if you installed GNU GCC with Homebrew.

  • When in doubt, check versions: g++ --version, clang --version, or cl.


FAQ (short)

Q: Which compiler should I use?
A: For Windows, MSVC (Visual Studio) is common. For cross-platform and Linux/macOS, GCC or Clang are standard. Use the toolchain that matches your deployment target.

Q: How do I use CMake?
A: Install CMake (sudo apt install cmake or brew install cmake or via Visual Studio installer) and create a CMakeLists.txt. Use cmake to configure and cmake --build . to build.

Q: How do I target a specific C++ standard?
A: Use compiler flags: -std=c++17, -std=c++20 (GCC/Clang) or /std:c++17 (MSVC).


Final notes

Keep your toolchain updated, pick an editor/IDE you like, and practice compiling small programs until you're comfortable with the terminal-based workflow. Happy coding!

Article