C Setup and Installation

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)

  1. Download MinGW from MinGW official site.
  2. Run the installer and select mingw32-gcc-g++ and mingw32-gcc-gfortran packages.
  3. Click “Apply Changes” and wait for installation.
  4. Add C:\MinGW\bin to your system’s PATH environment variable.

macOS (Using Homebrew)

  1. Install Homebrew if you haven’t already.
  2. Open Terminal and run: brew install gcc

Linux (Ubuntu/Debian)

  1. Open Terminal.
  2. 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

Try It Now

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;
}

Try It Now

To compile the program, run:

gcc hello.c -o hello

Try It Now

Then run the output file:

./hello

Try It Now