codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ installation

C++ installation

Full step-by-step installation for Windows, macOS and Linux.

Windows (MSYS2)

  1. Open msys2.org and download the installer.
  2. Run it, keep the default folder C:\msys64 and finish.
  3. Open MSYS2 UCRT64 from the Start menu and run pacman -S mingw-w64-ucrt-x86_64-gcc. Type Y to confirm.
  4. Add C:\msys64\ucrt64\bin to your PATH: open the Start menu, search Edit the system environment variables, click Environment Variables, select Path, click Edit, then New, and paste C:\msys64\ucrt64\bin.
  5. Close and reopen your terminal (Command Prompt or PowerShell).

macOS

  1. Open the Terminal app.
  2. Run xcode-select --install and click Install in the window that appears.
  3. Wait until the download finishes.

Linux (Ubuntu or Debian)

  1. Open a terminal and run sudo apt update.
  2. Run sudo apt install build-essential. On Fedora use sudo dnf install gcc gcc-c++.

Check the installation

  1. Open a new terminal.
  2. Run g++ --version. A version number means it works.

Run your first program

  1. Create a folder and a file named hello.cpp. Paste the code from the editor below.
  2. In the terminal, go to that folder with cd.
  3. Compile with g++ hello.cpp -o hello.
  4. Run it with ./hello (on Windows use hello.exe).

If something goes wrong

Example code

#include <iostream>
using namespace std;

int main() {
  cout << "C++ is installed" << endl;
  return 0;
}

Run this code in the online editor

← C++ introduction and get startedC++ syntax and comments →