Last Updated: April 21, 2025
Before writing your first C program, you need to set up your environment by installing a C compiler. This guide shows how to install and configure a C compiler on Windows, macOS, and Linux.
Step 1: Install a C Compiler
Windows (Using MinGW)
- Download MinGW from MinGW official site.
- Run the installer and select mingw32-gcc-g++ and mingw32-gcc-gfortran packages.
- Click “Apply Changes” and wait for installation.
- Add
C:\MinGW\bin
to your system’s PATH environment variable.
macOS (Using Homebrew)
- Install Homebrew if you haven’t already.
- Open Terminal and run:
brew install gcc
Linux (Ubuntu/Debian)
- Open Terminal.
- Run the following command:
sudo apt update && sudo apt install build-essential
Step 2: Verify Installation
After installation, open a terminal or command prompt and type:
gcc --version
If the version information appears, your compiler is successfully installed.
Step 3: Write Your First C Program
Create a file named hello.c
and write the following code:
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
To compile the program, run:
gcc hello.c -o hello
Then run the output file:
./hello