Step-by-step instructions to get C running on Windows, Mac, and Linux.
Download the installer from the official MSYS2 site and run it.
The default install location (C:\msys64) is fine.
Open the MSYS2 terminal and run the following:
Open "Edit the system environment variables" and add this to Path:
Open a new Command Prompt or PowerShell and run:
If you see the version info, you're good to go.
Open PowerShell as Administrator and run the command below. You'll need to reboot afterward.
In the WSL terminal (Ubuntu), run:
Open Terminal and run:
Click "Install" in the dialog that pops up. Expect it to take a few minutes.
If the version info prints, you're done. On Mac, gcc is really Apple Clang (a C-compatible compiler).
Ubuntu / Debian family:
Fedora / RHEL family:
Arch Linux:
Download the installer for your OS from the official Visual Studio Code site and run it.
Open VSCode, click the Extensions icon (four squares) on the left sidebar, then search for and install:
Open the VSCode terminal (Ctrl+`) and follow the next section to compile and run your code.
Create a file named hello.c with this content:
#include <stdio.h> int main(void) { printf("Hello, World!\n"); return 0; }
In the terminal, cd into the folder containing hello.c and run:
If there are no errors, an executable named hello (or hello.exe on Windows) appears.
On Windows, type .\hello.exe or just hello.
Your PATH isn't set correctly. Add C:\msys64\ucrt64\bin to the Path environment variable, then open a fresh Command Prompt.
The Command Line Tools aren't installed. Run xcode-select --install again.
The file isn't marked as executable. Run chmod +x hello, then try ./hello again.
Save your source file as UTF-8. Alternatively, compile with gcc -fexec-charset=CP932.
Check your understanding of this lesson!
xcode-select --install installs Apple's official Command Line Tools, giving you clang / gcc.
hello.c into an executable named hello?The -o flag sets the output file name. Without it, you end up with a.out.
-Wall turns on the standard set of warnings. Pair it with -Wextra for even stricter checks.