Setting up MinGW on Windows
What you'll learn: How to install the MinGW-w64 compiler so your computer can translate C code into working programs.
The Translator for Your Computer
Think of your computer as a high-speed worker who only speaks a language called "Machine Code" (long strings of ones and zeros). You, the programmer, speak C. To get the worker to do anything, you need a middleman to translate your C files into those ones and zeros. On Windows, the most popular free "translator" for this job is MinGW (Minimalist GNU for Windows).
Without MinGW, your computer sees a .c file as just a plain text document, like a grocery list. With it, those text files become functional .exe programs.
Step 1: Installation
The simplest way to get MinGW is through a project called MSYS2, which manages the installation for you.
- Download the installer from msys2.org.
- Follow the setup wizard, then open the terminal window it provides (it looks like a black box).
- Type this command:
pacman -S mingw-w64-ucrt-x86_64-gccand hit Enter. - Follow the prompts to finish the installation.
Step 2: Setting the Path
Installing the tool is like buying a new power tool and putting it in a shed. If you want to use it from anywhere in your yard (or in any folder on your computer), you need to tell Windows exactly where that shed is.
- Search for "Edit the system environment variables" in your Start menu.
- Click Environment Variables, find the Path variable under "System variables," and click Edit.
- Add the location where MinGW was installed (usually
C:\msys64\ucrt64\bin).
Step 3: The Verification
To make sure your "translator" is ready for work, open a new Command Prompt and type:
gcc --version
If you see a wall of text starting with "gcc (Rev...)", congratulations! You’ve successfully linked your human-readable logic to your computer’s binary brain. You are now ready to compile your first program.
Key takeaway
MinGW is the compiler that turns your C text into executable programs, but you must add it to your System Path so your computer can find it.