How to Install GCC Compiler on Windows Using MSYS2 (Step-by-Step Guide)

Terminal showing MSYS2 installation and GCC version output on a Windows PC, used for setting up a C compiler.
Step-by-step guide for installing GCC on Windows using the MSYS2 environment.

How to Install GCC Using MSYS2 on Windows

Great choice! MSYS2 is a powerful and flexible environment for GCC development on Windows. Here’s a step-by-step guide to install GCC using MSYS2:

How to Install GCC Using MSYS2 on Windows

Step 1: Download and Install MSYS2

  1. Go to the official MSYS2 website:
    👉 https://www.msys2.org
  2. Download the installer for 64-bit Windows:
    • msys2-x86_64-XXXXXX.exe (where XXXXXX is the version number)
  3. Run the installer and install MSYS2 to a simple directory like:
    C:\msys64

     

Step 2: Update MSYS2 Package Database

  1. Open the MSYS2 MSYS terminal from the Start menu (search for MSYS2 MSYS).
  2. Run the following command to update the core system:
    pacman -Syu
  3. If you’re prompted to close the window after this update, do so.
  4. Then reopen MSYS2 MSYS and run:
    pacman -Su

Step 3: Install the GCC Compiler (C/C++)

  1. In the MSYS2 terminal, install GCC with:
    pacman -S mingw-w64-x86_64-gcc

    This installs the 64-bit version of GCC (recommended). If you need 32-bit for some reason, use:

    pacman -S mingw-w64-i686-gcc

Step 4: Use GCC

  1. Open the terminal:
    MSYS2 MinGW 64-bit from the Start Menu (this is important — don’t use the plain “MSYS” terminal for compiling).
  2. In that terminal, test GCC:
    gcc --version

    Now compile a simple C program:

    • Create a file called hello.c:
      #include <stdio.h> 
      int main()
      { 
      printf("Hello, MSYS2!\n"); 
      return 0; 
      }

       

    • Compile and run:
      gcc hello.c -o hello.exe 
      ./hello.exe

       

Tip: Optional Useful Packages

You can also install other useful tools like:

pacman -S make gdb git vim