🇯🇵 日本語 | 🇺🇸 English
Advertisement

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 broadly need two things.
⚙️
Compiler (gcc)
The software that turns C source code into an executable program.
📝
Text editor
An editor for writing code. VSCode is recommended.
Lesson pages on this site include an in-browser code editor, so you can start learning without any setup.
But for serious development, a local environment is a must.

Installing the Compiler by OS

Select your OS below.
On Windows, you install gcc via MinGW-w64 or WSL (Windows Subsystem for Linux).
For beginners, MinGW-w64 is recommended.

Option A: MinGW-w64 (easy, recommended)

1
Download MSYS2

Download the installer from the MSYS2 official site and run it.
You can keep the default install location (C:\msys64).

2
Install gcc

Open the MSYS2 terminal and run:

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

Open "Edit the system environment variables" and add the following 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 version info, you are good to go.

Option B: WSL (use a Linux environment)

1
Enable WSL

Open PowerShell as Administrator and run the following. A reboot is required.

> wsl --install
2
Install gcc

In the WSL terminal (Ubuntu), run:

$ sudo apt update && sudo apt install gcc -y
On Mac, installing the Xcode Command Line Tools gives you gcc (actually clang).
1
Install Command Line Tools

Open Terminal and run:

$ xcode-select --install

Click "Install" in the dialog that appears. It takes a few minutes.

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

If version info prints, you are done. The gcc on Mac is Apple Clang (a C-compatible compiler).

You can also install the real GNU gcc via Homebrew, but clang from Xcode is more than enough for beginners.
Many Linux distributions come with gcc preinstalled. If not, install it via 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 Configuration

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

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

2
Install the C/C++ extension

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

3
Compile and run from the terminal

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

Your First Compile and Run

Once setup is finished, write a Hello World program and run it.
1
Create a file

Create a file named hello.c with the following content.

#include <stdio.h>

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

In the terminal, go to the folder that contains hello.c and run:

$ gcc hello.c -o hello

If there are no errors, hello (or hello.exe on Windows) is produced.

3
Run
$ ./hello
Hello, World!

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

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

If Setup Feels Like a Hassle (Online Compilers)

If you want to try C right now or got stuck on setup, these online services let you run C in your browser.
Wandbox
Supports multiple versions of gcc/clang. Compile options are freely configurable.
paiza.io
Supports standard input, so you can even practice scanf.
Compiler Explorer
Shows the assembly alongside your code. Advanced, but useful for understanding how compilation works.
Every lesson page on this site also has an in-browser code editor. Starting there is a perfectly fine first step.

Common Troubles

'gcc' is not recognized (Windows)

PATH is not set correctly. Add C:\msys64\ucrt64\bin to the Path environment variable, then open a new Command Prompt.

xcrun: error: invalid active developer path (Mac)

Command Line Tools are not installed. Run xcode-select --install again.

permission denied: ./hello

The file has no execute permission. Run chmod +x hello and 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
Share this article
Share on X Share on Facebook