🇯🇵 日本語 | 🇺🇸 English

C Programming Setup Guide

Step-by-step instructions to get C running on Windows, Mac, and Linux.

What You Need to Run C

To run a C program, you need two things.
⚙️
Compiler (gcc)
The tool that turns your C source code into an executable program.
📝
Text editor
Where you actually write your code. We recommend VSCode.
Every lesson page on this site includes an in-browser code editor, so you can start learning right away with zero setup.
That said, for serious development you'll want a proper local environment.

Installing the Compiler by OS

Pick your OS below.
On Windows, you can install gcc through either MinGW-w64 or WSL (Windows Subsystem for Linux).
For beginners, we recommend MinGW-w64.

Option A: MinGW-w64 (easy, recommended)

1
Download MSYS2

Download the installer from the official MSYS2 site and run it.
The default install location (C:\msys64) is fine.

2
Install gcc

Open the MSYS2 terminal and run the following:

$ pacman -S mingw-w64-ucrt-x86_64-gcc
3
Add to PATH

Open "Edit the system environment variables" and add this to Path:

C:\msys64\ucrt64\bin
4
Verify

Open a new Command Prompt or PowerShell and run:

> gcc --version
gcc (Rev..., Built by MSYS2 project) 13.x.x ...

If you see the version info, you're good to go.

Option B: WSL (use a Linux environment)

1
Enable WSL

Open PowerShell as Administrator and run the command below. You'll need to reboot afterward.

> wsl --install
2
Install gcc

In the WSL terminal (Ubuntu), run:

$ sudo apt update && sudo apt install gcc -y
On macOS, installing the Xcode Command Line Tools gives you gcc (which is actually Apple's clang behind the scenes).
1
Install Command Line Tools

Open Terminal and run:

$ xcode-select --install

Click "Install" in the dialog that pops up. Expect it to take a few minutes.

2
Verify
$ gcc --version
Apple clang version 15.x.x ...

If the version info prints, you're done. On Mac, gcc is really Apple Clang (a C-compatible compiler).

You can also install the "real" GNU gcc via Homebrew, but Xcode's clang is more than enough for beginners.
Most Linux distros ship with gcc preinstalled. If yours doesn't, grab it from your package manager.
1
Install gcc

Ubuntu / Debian family:

$ sudo apt update && sudo apt install gcc -y

Fedora / RHEL family:

$ sudo dnf install gcc -y

Arch Linux:

$ sudo pacman -S gcc
2
Verify
$ gcc --version
gcc (Ubuntu 13.2.0-...) 13.2.0 ...

Visual Studio Code Setup

VSCode is a free, feature-packed code editor. Here are the extensions we recommend for C.
1
Install VSCode

Download the installer for your OS from the official Visual Studio Code site and run it.

2
Install the C/C++ extension

Open VSCode, click the Extensions icon (four squares) on the left sidebar, then search for and install:

3
Compile and run from the terminal

Open the VSCode terminal (Ctrl+`) and follow the next section to compile and run your code.

Your First Compile and Run

With setup out of the way, let's write a Hello World program and run it.
1
Create a file

Create a file named hello.c with this content:

#include <stdio.h>

int main(void) {
    printf("Hello, World!\n");
    return 0;
}
2
Compile

In the terminal, cd into the folder containing hello.c and run:

$ gcc hello.c -o hello

If there are no errors, an executable named hello (or hello.exe on Windows) appears.

3
Run
$ ./hello
Hello, World!

On Windows, type .\hello.exe or just hello.

🎉
Setup complete!
You can now write and run C programs freely on your own machine.

If Setup Feels Like a Hassle (Online Compilers)

If you just want to try C right now, or if setup isn't cooperating, these online services let you run C straight from your browser.
Wandbox
Supports multiple versions of gcc and clang, with fully configurable compile options.
paiza.io
Supports standard input, so you can practice scanf too.
Compiler Explorer
Shows the generated assembly right next to your code. A bit advanced, but great for seeing how compilation actually works.
Every lesson page on this site also ships with an in-browser code editor. Starting there is a perfectly good first step.

Common Problems

'gcc' is not recognized (Windows)

Your PATH isn't set correctly. Add C:\msys64\ucrt64\bin to the Path environment variable, then open a fresh Command Prompt.

xcrun: error: invalid active developer path (Mac)

The Command Line Tools aren't installed. Run xcode-select --install again.

permission denied: ./hello

The file isn't marked as executable. Run chmod +x hello, then try ./hello again.

Garbled output (Windows)

Save your source file as UTF-8. Alternatively, compile with gcc -fexec-charset=CP932.

Open the Compile Errors Dictionary Proceed to the Hello World lesson

Review Quiz

Check your understanding of this lesson!

Q1. What's the standard command to install a C compiler on macOS?

xcode-select --install
brew install c
gcc init

xcode-select --install installs Apple's official Command Line Tools, giving you clang / gcc.

Q2. Which command compiles hello.c into an executable named hello?

gcc hello.c -o hello
run hello.c
c-compile hello.c

The -o flag sets the output file name. Without it, you end up with a.out.

Q3. Which gcc option enables most warnings?

-Wall
-warn
-debug

-Wall turns on the standard set of warnings. Pair it with -Wextra for even stricter checks.

Share this article
Share on X Share on Facebook