Setup: installing GCC/Clang & an editor
10 min lesson
- To write and run C programs, you need two tools: a compiler (GCC or Clang) and a text editor or IDE.
- GCC (GNU Compiler Collection) and Clang are the most common C compilers; GCC is default on Linux, Clang on macOS.
- A compiler translates your C source code into an executable file that the computer can run.
- A text editor is where you type your code; an IDE (Integrated Development Environment) combines an editor, compiler, and debugger in one program.
- On Windows, you can install MinGW-w64 (which includes GCC) or use WSL (Windows Subsystem for Linux).
- On macOS, install Xcode Command Line Tools by running xcode-select --install in Terminal; this gives you Clang.
- On Linux, use your package manager: sudo apt install build-essential (Debian/Ubuntu) or sudo dnf install gcc (Fedora).
- After installing, verify by opening a terminal and typing gcc --version; you should see version information.
- Good beginner editors include VS Code, Code::Blocks, and Sublime Text; VS Code is free and has a C/C++ extension.
- Create a folder for your C projects, for example ~/c-projects, to keep files organized.
- There is no code in this lesson because setup is about tools, not writing a C program yet.
- You need a compiler and an editor to write C programs.
- GCC and Clang are the standard compilers; install one and confirm it works with gcc --version.
- VS Code is a friendly, free editor that works on all platforms.
- If installation fails, read the error message carefully and search for the exact text; it is usually a missing package or path issue.
Breaking it down
Compiler
gcc --versionThe compiler checks your code for errors and turns it into an executable. Without it, you cannot run any C program. Verify it is installed by checking its version.
Text editor
VS Code, Code::BlocksThis is where you type your code. A good editor highlights syntax and helps you spot typos. An IDE adds a compiler and debugger in the same window.
Terminal
Command Prompt (Windows), Terminal (macOS/Linux)You use the terminal to run the compiler command and then run the executable. It is a text-based way to talk to your computer.
Project folder
mkdir ~/c-projectsA dedicated folder keeps your .c files and executables together. Without it, files get scattered and hard to find.
A helpful analogy
Setting up C is like setting up a kitchen before cooking. The compiler is your stove (it turns raw ingredients into a meal), and the editor is your cutting board (where you prepare the ingredients). You need both before you can cook your first dish.
Nesting rules
- 1.Always install the compiler before the editor, because the editor often needs to find the compiler to build your code.
- 2.On Windows, add MinGW-w64 to your PATH environment variable so you can run gcc from any folder.
- 3.Keep your source files (.c) separate from compiled executables (.exe or no extension) to avoid confusion.
Common mistakes
Installing an editor but no compiler
Avoid
Installing VS Code and expecting it to compile C out of the boxUse instead
Install GCC or Clang separately, then configure VS Code to use itEditors do not include a compiler by default. Without a compiler, you cannot turn .c files into runnable programs.
Not adding the compiler to PATH on Windows
Avoid
Typing gcc in Command Prompt and getting 'gcc is not recognized'Use instead
Add C:\MinGW\bin to the PATH environment variableThe system needs to know where the compiler executable lives. PATH tells it where to look.
Using spaces or special characters in project folder names
Avoid
C:\My Projects\C Code\Use instead
C:\c-projects\Spaces can break compiler commands in some setups. Keep folder names simple and use hyphens instead of spaces.
Quick tips
- •After installing, run gcc --version and clang --version to confirm which compilers are available.
- •In VS Code, install the C/C++ extension by Microsoft for syntax highlighting and error checking.
- •Create a new folder for each practice project so files do not mix.
- •If you are on Windows and struggle with MinGW, try WSL: it gives you a Linux terminal with GCC already available.
- •Bookmark the compiler's documentation page; you will refer to it often.