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
- Go to the official MSYS2 website:
👉 https://www.msys2.org - Download the installer for 64-bit Windows:
msys2-x86_64-XXXXXX.exe
(whereXXXXXX
is the version number)
- Run the installer and install MSYS2 to a simple directory like:
C:\msys64
Step 2: Update MSYS2 Package Database
- Open the MSYS2 MSYS terminal from the Start menu (search for
MSYS2 MSYS
). - Run the following command to update the core system:
pacman -Syu
- If you’re prompted to close the window after this update, do so.
- Then reopen MSYS2 MSYS and run:
pacman -Su
Step 3: Install the GCC Compiler (C/C++)
- 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
- Open the terminal:
MSYS2 MinGW 64-bit from the Start Menu (this is important — don’t use the plain “MSYS” terminal for compiling). - 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
- Create a file called
Tip: Optional Useful Packages
You can also install other useful tools like:
pacman -S make gdb git vim