C Notes
Step-by-step guide to install GCC C compiler on Windows using MinGW-w64, MSYS2, and WSL. Learn to set up your C programming environment on Windows 10/11 with PATH configuration.
Windows doesn't come with a C compiler pre-installed, but setting one up is straightforward. In this guide, we'll cover three popular methods to get GCC running on your Windows machine: MinGW-w64 (quickest), MSYS2 (most powerful), and WSL (full Linux environment). By the end, you'll be compiling and running C programs from your command prompt or terminal.
Method 1: MinGW-w64 (Recommended for Beginners)
MinGW-w64 (Minimalist GNU for Windows) provides a native Windows port of GCC. It's lightweight, easy to install, and produces native Windows executables without needing any extra runtime libraries.
Step 1: Download MinGW-w64
- Visit the official MinGW-w64 builds page: https://www.mingw-w64.org/downloads/
- For the easiest experience, download the WinLibs standalone build from https://winlibs.com/
- Choose the latest Release version with UCRT runtime (recommended for Windows 10/11)
- Select Win64 → Zip archive
- Download the zip file (approximately 300-400 MB)
Step 2: Extract the Archive
- Create a folder:
C:\mingw64 - Extract the downloaded zip file into this folder
- After extraction, you should see
C:\mingw64\bin\gcc.exe
Step 3: Add to System PATH
This is the most important step — without this, your terminal won't find the gcc command.
- Press Win + R, type
sysdm.cpl, and press Enter - Go to the Advanced tab
- Click Environment Variables
- Under System Variables, find and select Path
- Click Edit → New
- Add:
C:\mingw64\bin - Click OK on all dialogs to save
Alternatively, you can use PowerShell (as Administrator):
Step 4: Verify Installation
Open a new Command Prompt or PowerShell window (important — existing windows won't see the PATH change) and type:
gcc --versiongcc (MinGW-W64 x86_64-ucrt-posix-seh) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions.
If you see version information, congratulations — GCC is installed!
Step 5: Test with a Program
Create a file called hello.c:
#include <stdio.h>
int main() {
printf("Hello from Windows!\n");
printf("GCC is working correctly.\n");
return 0;
}Compile and run:
gcc hello.c -o hello.exe
hello.exeHello from Windows! GCC is working correctly.
Method 2: MSYS2 (Recommended for Serious Development)
MSYS2 provides a full Unix-like environment on Windows with a package manager (pacman). It's ideal if you need additional tools like Make, Git, CMake, or various libraries.
Step 1: Download MSYS2
- Go to https://www.msys2.org/
- Download the installer (e.g.,
msys2-x86_64-20240113.exe) - Run the installer
- Install to the default location:
C:\msys2 - Complete the installation and launch MSYS2
Step 2: Update the System
In the MSYS2 terminal that opens, run:
pacman -SyuThe terminal may close after updating core packages. Reopen MSYS2 UCRT64 from the Start menu and run again:
pacman -SuStep 3: Install GCC and Development Tools
pacman -S mingw-w64-ucrt-x86_64-gcc
pacman -S mingw-w64-ucrt-x86_64-gdb
pacman -S makeOr install the complete development toolchain at once:
pacman -S mingw-w64-ucrt-x86_64-toolchainWhen prompted, press Enter to install all packages in the group.
Step 4: Add MSYS2 to System PATH
Add this path to your system PATH (same process as MinGW above):
Step 5: Verify in Command Prompt
Open a new Command Prompt:
gcc --version
gdb --version
make --versionAll three commands should show version information.
Method 3: WSL (Windows Subsystem for Linux)
WSL gives you a full Linux environment running inside Windows. This is the best option if you want the authentic Linux development experience or plan to work with Linux-specific tools.
Step 1: Enable WSL
Open PowerShell as Administrator and run:
wsl --installThis installs WSL2 with Ubuntu by default. Restart your computer when prompted.
Step 2: Set Up Ubuntu
After restart, Ubuntu will launch automatically and ask you to create a username and password. Complete the setup.
Step 3: Install GCC
In the Ubuntu terminal:
sudo apt update
sudo apt install build-essentialThe build-essential package includes GCC, G++, Make, and other essential development tools.
Step 4: Verify Installation
gcc --versiongcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc.
Step 5: Access Windows Files from WSL
Your Windows drives are mounted under /mnt/:
cd /mnt/c/Users/YourName/DocumentsYou can create and compile C files that live on your Windows filesystem.
Comparison of Methods
| Feature | MinGW-w64 | MSYS2 | WSL |
|---|---|---|---|
| Setup Difficulty | Easy | Medium | Easy |
| Disk Space | ~500 MB | ~1-2 GB | ~2-5 GB |
| Package Manager | None | pacman | apt |
| Native Windows EXE | ✅ Yes | ✅ Yes | ❌ No (Linux binaries) |
| Unix Tools | Limited | Full | Full |
| IDE Integration | Excellent | Good | Good |
| Performance | Native | Native | Near-native |
| Best For | Beginners | Advanced users | Linux development |
Troubleshooting Common Issues
"gcc is not recognized as a command"
This means the PATH is not set correctly. Solutions:
- Make sure you opened a new terminal after setting PATH
- Verify the path exists: check if
C:\mingw64\bin\gcc.exeactually exists - Check for typos in the PATH entry
- Try restarting your computer
"Cannot find -lgcc"
This usually means an incomplete installation. Reinstall MinGW-w64 using the complete package from WinLibs.
Antivirus Blocking GCC
Some antivirus programs flag GCC executables as suspicious. Add your MinGW folder to your antivirus exclusion list.
32-bit vs 64-bit Confusion
Always use the 64-bit (x86_64) version unless you specifically need 32-bit. Most modern Windows systems are 64-bit.
Verifying Everything Works
Run this complete test to make sure your setup is correct:
#include <stdio.h>
#include <math.h>
int main() {
printf("=== C Compiler Test ===\n");
printf("Compiler: GCC\n");
printf("Platform: Windows\n");
printf("sqrt(144) = %.0f\n", sqrt(144));
printf("sizeof(int) = %zu bytes\n", sizeof(int));
printf("sizeof(long) = %zu bytes\n", sizeof(long));
printf("sizeof(pointer) = %zu bytes\n", sizeof(void*));
printf("=== All tests passed! ===\n");
return 0;
}Compile with the math library:
gcc test.c -o test.exe -lm
test.exe=== C Compiler Test === Compiler: GCC Platform: Windows sqrt(144) = 12 sizeof(int) = 4 bytes sizeof(long) = 4 bytes sizeof(pointer) = 8 bytes === All tests passed! ===
Interview Questions
Q1: What is MinGW and why is it needed on Windows?
MinGW (Minimalist GNU for Windows) is a port of the GNU Compiler Collection (GCC) for Windows. It's needed because Windows doesn't include a C compiler by default. MinGW provides gcc, g++, and other GNU tools that produce native Windows executables without requiring any special runtime DLLs like Cygwin does.
Q2: What is the difference between MinGW and MSYS2?
MinGW provides just the compiler and basic tools. MSYS2 is a complete software distribution that includes MinGW plus a Unix-like shell environment, the pacman package manager (from Arch Linux), and easy access to thousands of pre-compiled libraries and tools. MSYS2 is more powerful but requires more disk space.
Q3: What is WSL and how does it differ from MinGW for C programming?
WSL (Windows Subsystem for Linux) runs a full Linux kernel inside Windows, giving you a complete Linux environment. Programs compiled in WSL produce Linux ELF binaries (not Windows .exe files). MinGW produces native Windows executables. WSL is preferred when developing for Linux servers or when you need Linux-specific system calls, while MinGW is preferred for native Windows development.
Q4: Why do we need to add GCC to the system PATH?
The system PATH is an environment variable that tells the operating system where to find executable programs. When you type gcc in the terminal, the OS searches through all directories listed in PATH to find gcc.exe. Without adding the GCC installation directory to PATH, you'd have to type the full path (e.g., C:\mingw64\bin\gcc.exe) every time.
Q5: What does the build-essential package contain in Ubuntu/WSL?
The build-essential meta-package includes GCC (C compiler), G++ (C++ compiler), Make (build automation tool), libc6-dev (C standard library headers), and dpkg-dev (Debian package development tools). It provides everything needed to compile C and C++ programs from source code on Debian-based systems.
Summary
- Windows requires manual installation of a C compiler — GCC via MinGW-w64 is the most common choice
- MinGW-w64 is best for beginners who just need to compile C programs quickly
- MSYS2 is best for developers who need a full Unix toolchain with package management
- WSL is best for those who want a complete Linux development environment on Windows
- Always add the compiler's
bindirectory to your system PATH - Open a new terminal window after modifying PATH for changes to take effect
- Test your installation with a simple Hello World program before proceeding
- Use 64-bit versions on modern Windows systems
With your compiler installed, you're ready to start writing and compiling C programs on Windows. The next step is setting up a proper code editor like VS Code for a comfortable development experience.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Install C Compiler on Windows - MinGW, MSYS2, and WSL Guide.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this C Programming topic.
Search Terms
c-programming, c programming, programming, setup, install, windows, install c compiler on windows - mingw, msys2, and wsl guide
Related C Programming Topics