How to Run a C File in Terminal: A Complete Guide
Running a C program from the terminal is a foundational skill for anyone learning systems programming, computer science, or software development. Unlike interpreted languages such as Python, C is a compiled language — meaning your source code must be translated into machine code before it can execute. That two-step process (compile, then run) is what trips up most beginners.
Here's exactly how it works, what affects the process, and where your specific setup matters.
Understanding the Compile-Then-Run Model
When you write a .c file, you're writing human-readable source code. The terminal can't execute that directly. You need a compiler — a program that reads your .c file and produces an executable binary your operating system can actually run.
The most common compiler is GCC (GNU Compiler Collection), available on Linux and macOS. On Windows, you typically use GCC through environments like MinGW, Cygwin, or WSL (Windows Subsystem for Linux). macOS also ships with Clang, which behaves nearly identically to GCC for most purposes.
Step-by-Step: Compiling and Running a C File
Step 1 — Check That a Compiler Is Installed
Open your terminal and type: