How to Install GCC on Windows 11 or 10 (MSYS2 and MinGW-w64)

The easiest way to install GCC on Windows 11 or Windows 10 is through MSYS2, which provides an up-to-date MinGW-w64 version of GCC. Install MSYS2 from msys2.org, open the MSYS2 UCRT64 terminal, and run pacman -S mingw-w64-ucrt-x86_64-gcc. Then add C:\msys64\ucrt64\bin to your Windows Path so you can run gcc and g++ from Command Prompt, PowerShell, or VS Code. Type gcc --version to confirm it worked.

Which option is right for you?

Option Best for
MSYS2 (MinGW-w64 GCC) Most people who want gcc and g++ on Windows
WSL (Linux GCC) Linux-style development and tools like make
Visual Studio (MSVC) Windows apps and the Visual Studio IDE, not GCC

Method 1: Install GCC with MSYS2

Step 1: Install MSYS2

  1. Go to msys2.org and download the installer, or run winget install MSYS2.MSYS2 in Terminal.
  2. Run the installer and keep the default folder, C:\msys64.
  3. When it finishes, leave Run MSYS2 now checked and click Finish.

Step 2: Update MSYS2 and install GCC

  1. Open MSYS2 UCRT64 from the Start menu.
  2. Run pacman -Syu to update. If the window closes, open MSYS2 UCRT64 again and run pacman -Syu once more.
  3. Run pacman -S mingw-w64-ucrt-x86_64-gcc and press Enter, then Y to confirm.
  4. Run gcc --version. You should see the installed version.
MSYS2 UCRT64 terminal installing GCC with pacman and a Windows Terminal showing gcc --version
(1) Install GCC with pacman, then (2) check the version. (Illustration)

For debugging and build tools too, run pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain. This adds gdb, make, and more.

Step 3: Add GCC to your Windows Path

  1. Click Start, type environment variables, and open Edit the system environment variables.
  2. Click Environment Variables.
  3. Under User variables, select Path and click Edit.
  4. Click New, type C:\msys64\ucrt64\bin, and click OK in each window.
  5. Open a new Command Prompt or PowerShell window and run gcc --version and g++ --version.

Test it with a Hello World program

  1. Create a file named hello.c with this code:
    #include <stdio.h>
    int main(void) { printf("Hello, world!\n"); return 0; }
  2. In the same folder, run gcc hello.c -o hello.exe.
  3. Run .\hello.exe. You should see Hello, world!

For C++, save the file as hello.cpp and compile with g++ hello.cpp -o hello.exe.

Method 2: Use GCC in WSL

  1. Open Terminal (Admin) and run wsl --install. Restart when asked.
  2. Open Ubuntu from the Start menu and create a Linux username and password.
  3. Run sudo apt update, then sudo apt install build-essential.
  4. Run gcc --version to confirm.

Programs built in WSL are Linux programs. They run inside WSL, not as regular Windows .exe files.

Use GCC with VS Code

  1. Install Visual Studio Code and the C/C++ extension from Microsoft.
  2. Open your project folder, open a .c or .cpp file, and choose Run > Run Without Debugging.
  3. When asked, choose the C/C++: gcc.exe or g++.exe build task from C:\msys64\ucrt64\bin.

Troubleshooting

  • “gcc is not recognized”: The Path isn’t set or you’re using an old window. Recheck Step 3 and open a new terminal.
  • Wrong gcc runs: An older MinGW is earlier in your Path. Run where gcc to see which one Windows finds, and remove the old folder from Path.
  • Antivirus flags your .exe: Brand-new compiled programs sometimes trigger false positives. Add your project folder as an exclusion if you trust the code.

Frequently asked questions

Is MinGW the same as GCC?

MinGW-w64 is a version of the GCC toolchain built to create Windows programs. MSYS2 is the easiest way to install and update it.

Should I use the old MinGW installer from SourceForge?

No. The original MinGW project is outdated. Use MinGW-w64 through MSYS2 instead.

What’s the difference between UCRT64 and MINGW64?

Both make 64-bit Windows programs. UCRT64 uses Microsoft’s newer Universal C Runtime and is the recommended default.

Is this the same on Windows 10?

Yes. The steps are identical on Windows 10 and Windows 11.