How to Install GCC on Windows 11 — MSYS2 and MinGW-w64 Setup

This guide shows you how to install GCC on Windows 11 so you can compile and run C programs. Windows does not ship with a C compiler, but you have two excellent free options: MinGW-w64 via MSYS2 (a native Windows GCC that produces regular .exe files) and WSL2 (a real Ubuntu Linux environment inside Windows). This guide covers both, step by step, and helps you pick the right one first.

Not ready to install anything yet? You can write and run C programs directly in your browser — see our guide to online C compilers. No installation needed, ideal if you just have one or two programs to compile.

Which Way Should You Install GCC?

Path A — MSYS2 (native) Path B — WSL2 (Ubuntu)
What you get GCC 16 running directly on Windows GCC 13 inside a genuine Ubuntu Linux
Programs you build Windows .exe files Linux (ELF) executables
Debugger GDB ✓ GDB ✓
Valgrind ✗ (not available on Windows)
Best for Building software for Windows; single-environment simplicity Coursework, interviews, and matching the Linux servers most C code runs on

Our recommendation: if you’re learning C for university, placements, or systems-programming interviews, use WSL2 — you’ll be working in the same environment as the graders, the servers, and every Linux tutorial (including our Valgrind guide, which simply can’t run natively on Windows). If you want to build programs that other Windows users can double-click, use MSYS2. Installing both is completely fine — they don’t conflict.

Path A — Native GCC with MSYS2

Why MSYS2 and Not the Old MinGW Installer?

If you have seen older tutorials pointing to “mingw-get” or a standalone MinGW installer, skip them. That project is no longer maintained and ships an ancient GCC version. MSYS2 gives you MinGW-w64 with a current GCC (16.1 as of mid-2026), security updates, and a simple package manager (pacman) to keep it up to date. This is what the GCC project itself recommends for Windows today.

Step 1 — Download MSYS2

Go to the official site msys2.org and download the installer (a file named something like msys2-x86_64-XXXXXXXX.exe). Always download from the official site — never from a mirror or third party.

Step 2 — Run the Installer

  1. Run the downloaded .exe
  2. Accept the default install location (C:\msys64) — this keeps later commands simple
  3. Click through Next until installation finishes
  4. Leave Run MSYS2 now ticked and click Finish

A dark terminal window opens. This is the MSYS2 shell — you will run the next commands here.

Step 3 — Update MSYS2

Before installing GCC, update the package database. In the MSYS2 terminal, type:

pacman -Syu

When prompted, type Y and press Enter. The terminal may close itself at the end of the update — this is normal. Reopen it from the Start menu (search for MSYS2 UCRT64) and run the update once more to finish:

pacman -Su

Step 4 — Install the GCC Toolchain

Now install MinGW-w64 GCC:

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

Press Enter to accept the default selection, then Y to confirm. This installs GCC, the C standard library, and supporting tools (the compiler package alone unpacks to roughly 180 MB).

To also get gdb (the debugger) and make in one go, install the full toolchain instead:

pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain

UCRT64 vs MINGW64 — Which Environment Is Which?

MSYS2 confusingly installs several Start-menu entries: MSYS2 UCRT64, MSYS2 MINGW64, MSYS2 MSYS, and more. They are parallel “environments” that differ in which C runtime your programs link against:

  • UCRT64 — links against the Universal C Runtime, the modern runtime that ships with Windows 10/11. Use this one. It’s the MSYS2 default recommendation, and it’s why this guide installs mingw-w64-ucrt-x86_64-gcc.
  • MINGW64 — links against the older MSVCRT runtime. Only needed for compatibility with old libraries.
  • MSYS — the internal POSIX shell for running pacman and Unix tools; its GCC builds Cygwin-style binaries, not native Windows ones. Don’t compile your C programs here.

The classic mistake: installing the UCRT64 compiler, then opening the plain MSYS shell and finding gcc: command not found. Each environment has its own PATH — always open the UCRT64 shell (or set up Windows PATH as in Step 5 and use any terminal).

Step 5 — Add GCC to the Windows PATH

So you can run gcc from any terminal (Command Prompt, PowerShell, or VS Code) — not just the MSYS2 shell — add it to your PATH:

  1. Press Win and type environment variables
  2. Click Edit the system environment variables
  3. Click Environment Variables…
  4. Under System variables, select Path and click Edit
  5. Click New and add: C:\msys64\ucrt64\bin
  6. Click OK on all dialogs

Close and reopen any terminal windows for the change to take effect.

Step 6 — Verify the Installation

Open a regular Command Prompt or PowerShell (not the MSYS2 shell) and type:

gcc --version

You should see something like:

gcc.exe (Rev5, Built by MSYS2 project) 16.1.0
Copyright (C) 2026 Free Software Foundation, Inc.

If you see a version number, GCC is installed and on your PATH. If you get 'gcc' is not recognized, recheck Step 5 — the PATH entry must point to C:\msys64\ucrt64\bin.

Step 7 — Compile and Run Your First Program

Create a file called hello.c in any folder with this content:

#include <stdio.h>

int main(void) {
    printf("Hello from Windows 11!\n");
    return 0;
}

Open Command Prompt, navigate to that folder with cd, and run:

gcc hello.c -o hello.exe
hello.exe

Output:

Hello from Windows 11!

On Windows the executable ends in .exe, and you run it by typing its name (no ./ needed, unlike macOS and Linux).

Path B — GCC in WSL2 (Ubuntu on Windows)

WSL2 (Windows Subsystem for Linux) runs a real Ubuntu inside Windows 11 — not an emulation, an actual Linux kernel in a lightweight VM. You get the exact toolchain used on servers, in CS courses, and in every Linux-based C tutorial, while staying in Windows.

Step 1 — Install WSL

Open PowerShell as Administrator (right-click the Start button → Terminal (Admin)) and run:

wsl --install

This single command enables the required Windows features and installs Ubuntu (the default distribution). Restart your PC when prompted. On first launch, Ubuntu asks you to create a Linux username and password — these are separate from your Windows login.

Step 2 — Install the C Toolchain

In the Ubuntu terminal (search Ubuntu in the Start menu), install everything with one command:

sudo apt update
sudo apt install build-essential

build-essential brings gcc, make, the linker, and the standard library headers. Verify it:

$ gcc --version
gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.

(That’s the output on Ubuntu 24.04, the current WSL default. Yes, it’s an older GCC than MSYS2’s 16.1 — Ubuntu ships the version it has stabilized and security-patched. For learning C, the difference is irrelevant.)

Step 3 — Compile and Run

Exactly as on any Linux system:

$ gcc -o hello hello.c
$ ./hello
Hello from WSL!

Note the two Linux-isms: no .exe suffix, and the ./ prefix to run a program from the current directory. WSL builds Linux (ELF) executables — they run inside WSL, not by double-clicking in Windows. From here, our compile C on Linux guide applies to you word for word — warnings, the -lm linker trap, multi-file builds, all of it.

Working with Files

Your Ubuntu home directory lives at \\wsl$\Ubuntu\home\yourname in Windows Explorer, and your Windows drives appear as /mnt/c, /mnt/d inside Ubuntu. Best practice: keep C projects inside the Linux filesystem (your Ubuntu home) — it’s much faster than compiling across /mnt/c. If you use VS Code, install the WSL extension and run code . from any Ubuntu folder — the editor runs in Windows while the compiler and debugger run in Linux, seamlessly.

Common Issues

Problem Fix
'gcc' is not recognized as an internal or external command PATH not set — recheck Path A Step 5, then open a fresh terminal
gcc: command not found inside an MSYS2 shell You’re in the plain MSYS shell — open MSYS2 UCRT64 instead (see the UCRT64 vs MINGW64 section)
'pacman' is not recognized You are in Command Prompt, not the MSYS2 shell — run pacman commands in the MSYS2 terminal
The MSYS2 terminal closed during update Normal during pacman -Syu — reopen and run pacman -Su
First compile is slow (several seconds) Windows Defender scanning the new toolchain — normal; add an exclusion for C:\msys64 if it persists
Antivirus blocks the download MSYS2 is safe — download only from msys2.org and allow it through
Old MinGW already on PATH Remove the old MinGW PATH entry so it does not shadow the new GCC
wsl --install fails or WSL won’t start Virtualization is disabled — enable it in BIOS/UEFI (usually called Intel VT-x, AMD-V, or SVM), and make sure you ran PowerShell as Administrator
Compiling in /mnt/c is very slow (WSL) Cross-filesystem overhead — keep projects in the Ubuntu home directory instead

What’s Next

Now that GCC is installed, learn the full compile-and-run workflow — including warning flags and multiple source files — in our guide: How to Run a C Program on Windows 11 (for the MSYS2 path) or How to Compile C on Linux (for WSL).

Then level up your toolchain the way professionals do: debug with GDB, automate builds with a Makefile, and (on WSL) hunt memory bugs with Valgrind. Curious how GCC stacks up against the other big compiler? See GCC vs Clang.

Prefer a full IDE with code completion and one-click compiling instead of the command line? VS Code is the best free option and works seamlessly with both the MSYS2 GCC and WSL setups you just installed.

Once your environment is ready, browse our full list of C programs with examples to start practising.


As an Amazon Associate we earn from qualifying purchases.

Recommended Book

The best book to learn C once your environment is set up — The C Programming Language by Brian Kernighan and Dennis Ritchie (K&R). Concise, precise, and still the definitive reference decades on.

This guide is part of our Complete C Development Environment Setup Guide — the full step-by-step path from zero to writing C.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>