C++ Compiler Setup (GCC, MinGW, VS Code)
In this lesson: Set up C++ on Windows with MinGW/GCC and VS Code, or code online — run your first program in minutes. In Hindi & English.
What you need to run C++
To write and run C++ you need two things: a compiler (which turns your code into a runnable program) and a place to write the code (a text editor or IDE). The most widely used free compiler is g++, part of the GCC toolset.
You have three practical routes, from easiest to most complete: an online compiler, a local compiler with an editor, or a full IDE. We will cover each.
Fastest start: an online compiler
If you just want to start learning today, an online C++ compiler needs nothing installed. You type code in the browser, press Run, and see the output. It is ideal for the early lessons in this course. When your programs grow, move to a local setup below.
Windows: MinGW (GCC)
Windows has no built-in C++ compiler, so you install MinGW, which provides g++.
- Download and install MinGW (or the MSYS2 version of it).
- During install, include the C++ compiler component.
- Add its
binfolder to your system PATH sog++works in any terminal. - Open a new Command Prompt and type
g++ --versionto check it works.
If g++ is "not recognised," the PATH step was missed. Add the MinGW bin folder to PATH and reopen the terminal.
Linux and macOS: GCC
On most Linux systems the compiler is one command away:
sudo apt update sudo apt install g++
On macOS, installing Xcode Command Line Tools with xcode-select --install gives you a C++ compiler (clang, which understands the same commands).
Using VS Code
VS Code is a free, lightweight editor. Combined with a compiler like g++, it is a comfortable setup:
- Install VS Code and the official C/C++ extension.
- Make sure g++ is installed and on your PATH (see above).
- Open your
.cppfile and use the built-in terminal to compile and run.
Compiling and running
Whatever setup you use, the compile-and-run steps are the same. Save this as hello.cpp:
#include <iostream>
using namespace std;
int main() {
cout << "It works!" << endl;
return 0;
}Then in the terminal:
g++ hello.cpp -o hello # compile ./hello # run (Windows: hello.exe)
It works!
Common setup problems
- "g++ is not recognised" — the compiler is not on your PATH; add its
binfolder and reopen the terminal. - Editing the file but running an old compiled program — recompile after every change.
- Saving with the wrong extension — the file must end in
.cpp. - Forgetting to reopen the terminal after changing PATH, so it still cannot find g++.
Get any one setup working — online is fine to start — and successfully compile and run the hello.cpp above. Once you see "It works!", you are ready for the first C++ program lesson.
Summary
- Running C++ needs a compiler (usually g++) and an editor.
- An online compiler needs nothing installed and is great to start.
- On Windows, MinGW provides g++; on Linux/macOS it is one install command.
- VS Code plus the C/C++ extension makes a comfortable local setup.
- Compile with
g++ file.cpp -o name, then run the program.
Frequently Asked Questions
What do I need to run C++ programs?
What is the best C++ compiler for beginners?
Can I run C++ without installing anything?
How do I compile a C++ program with g++?
hello.cpp, then run g++ hello.cpp -o hello to compile it into a program named hello. Run it with ./hello on Linux or macOS, or hello.exe on Windows.What is MinGW and why is it needed on Windows?
g++ command that compiles your programs from the command line or an editor.