Install GCC/Clang & VS Code
To write C you need three things: a compiler that turns your code into a program, a terminal where you type commands, and an editor where you write code. The two most popular free C compilers are GCC (the GNU Compiler Collection) and Clang (part of the LLVM project). Both support the C23 standard used in this course.
This lesson shows how to install a compiler on Windows, Linux and macOS, how to set up Visual Studio Code, and how to check that everything works. Follow only the section for your own computer.
Which compiler version do you need?
C23 features arrived in compilers step by step. Recent versions support everything in this course:
| Compiler | What you get |
|---|---|
| GCC 13 | Most C23 features (nullptr, constexpr, bool keywords), using the option -std=c2x |
| GCC 14 | Accepts the option name -std=c23 |
| GCC 15 and newer | Uses C23 by default and adds #embed |
| Clang 19 and newer | Supports the C23 features used in this course with -std=c23 |
To be safe, always pass -std=c23 when you compile. Then your program is built as C23 even on a compiler whose default is an older standard.
Windows option 1: MSYS2 (GCC for Windows)
MSYS2 is a free collection of tools that brings GCC and other Linux-style tools to Windows. It needs 64-bit Windows 10 (version 1809 or newer) or Windows 11.
- Download the installer from the official site, msys2.org, and run it. Keep the default folder
C:\msys64. - When the installer finishes, a terminal window for the UCRT64 environment opens. If it does not, open "MSYS2 UCRT64" from the Start menu.
- Install GCC, the gdb debugger and make with the command below. Press Enter to accept all packages, then
Yto confirm. - Add the folder
C:\msys64\ucrt64\binto your WindowsPath: search Start for "Edit environment variables for your account", selectPath, click Edit, then New, paste the folder and click OK. - Close every terminal, open a new PowerShell window and check the versions.
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchaingcc --version
gdb --versionIf both commands print a version line, GCC is ready. MSYS2 has several environments; the ucrt64 packages produce normal Windows programs, so stay with them.
Windows option 2: WSL (Linux inside Windows)
The Windows Subsystem for Linux (WSL) runs a real Linux system, usually Ubuntu, inside Windows. Many C developers prefer it because the tools behave exactly as they do on Linux servers. Later lessons on debugging use sanitizers, compiler features that catch memory bugs, and these work best on Linux, so WSL is a good choice if your computer supports it.
Open PowerShell as administrator and run:
wsl --installRestart when asked, then open "Ubuntu" from the Start menu and choose a Linux user name and password. Now install the compiler and debugger inside Ubuntu, as shown in the next section.
Linux
On Ubuntu, Debian or Linux Mint, the build-essential package installs GCC, make and the C library headers. Add gdb for debugging and, if you like, Clang as a second compiler:
sudo apt update
sudo apt install build-essential gdb
sudo apt install clang
gcc --versionOn Fedora use sudo dnf install gcc make gdb, and on Arch Linux use sudo pacman -S base-devel gdb.
macOS
Apple provides Clang in the free Command Line Tools. Open the Terminal app and run:
xcode-select --install
clang --versionA window asks you to confirm the download. After it finishes, clang --version prints an "Apple clang version" line. On a Mac, the gcc command also exists, but it runs Apple Clang, not the real GCC. That is fine for this course. If you want the real GCC, the Homebrew package manager can install it with brew install gcc, and you then call it with a version number such as gcc-15. The Mac debugger is lldb rather than gdb; the commands are similar.
Set up VS Code
Visual Studio Code (VS Code) is a free editor from Microsoft that works on all three systems.
- Install VS Code from code.visualstudio.com.
- Open the Extensions view (
Ctrl+Shift+X, orCmd+Shift+Xon a Mac), search for "C/C++" and install the extension by Microsoft (its ID isms-vscode.cpptools). It adds code completion, error underlines and debugging support. - Create a folder for your C practice, for example
c-practice, and open it with File, Open Folder. - Open the Command Palette (
Ctrl+Shift+P), run "C/C++: Edit Configurations (UI)", set Compiler path to yourgccorclang, and set C standard toc23. - Open the built-in terminal with
Ctrl+`. You will compile and run programs from there.
If you use WSL, also install Microsoft's WSL extension, then type code . inside the Ubuntu terminal. VS Code then opens your Linux folder and uses the Linux compiler.
Test your setup
Create a file called hello.c in your practice folder with this code:
#include <stdio.h>
int main(void)
{
printf("My C compiler works!\n");
return 0;
}Compile and run it in the terminal. On Linux, macOS, WSL and the MSYS2 terminal:
gcc -std=c23 -Wall -Wextra hello.c -o hello
./helloMy C compiler works!
In PowerShell on Windows, GCC adds .exe to the program name, and you run it with .\hello.exe. On a Mac you can replace gcc with clang; the options are the same.
Common mistakes
- "gcc is not recognized" on Windows. The
Pathchange only reaches terminals opened after it. Close VS Code and every terminal, then open them again. Also check that the folderC:\msys64\ucrt64\binreally containsgcc.exe. - Installing the wrong MSYS2 package. Typing
pacman -S gccinstalls a GCC for the MSYS environment, whose programs depend on extra MSYS files. Use themingw-w64-ucrt-x86_64-...packages shown above. - Typing
helloinstead of./helloon Linux. Linux does not look for programs in the current folder, so you must give the path./. - A file called
hello.c.txt. Windows hides file extensions by default, and Notepad may add.txt. Create files from VS Code to avoid this.
Key points
- GCC and Clang are free C compilers; both support C23 in recent versions.
- On Windows, install GCC with MSYS2 (UCRT64) or use WSL for a full Linux environment.
- On Linux install
build-essentialandgdb; on macOS runxcode-select --installto get Clang. - Install VS Code with Microsoft's C/C++ extension and compile from its built-in terminal.
- Always compile with
-std=c23 -Wall -Wextraso you get modern C and helpful warnings.
Exercise
Install a compiler for your system and check its version with gcc --version or clang --version. Then change hello.c so that it prints two lines: your name on the first line and your city on the second. Compile it with -std=c23 -Wall -Wextra and run it.
Show solution
#include <stdio.h>
int main(void)
{
printf("Name: Ananya Sharma\n");
printf("City: Lucknow\n");
return 0;
}Name: Ananya Sharma City: Lucknow
Each printf call ends with \n, so the second line starts on a new line. If the compiler prints nothing and the program runs, your setup is complete.
Quick Quiz
1. Which folder must be added to the Windows Path after installing GCC with MSYS2 (UCRT64)?
The UCRT64 toolchain installs gcc.exe, gdb.exe and friends into C:\msys64\ucrt64\bin.
2. What does the gcc command run on a Mac with Apple's Command Line Tools?
Apple ships Clang and makes the gcc command point to it.
3. Why should you pass -std=c23 when you compile?
Different compiler versions have different default standards; -std=c23 makes the choice explicit.
4. On Ubuntu, which package installs GCC, make and the C library headers in one step?
sudo apt install build-essential installs the basic build tools for C on Debian and Ubuntu.
Learn C with a mentor
Free lessons get you started. Our Java, C & C++ Programming training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
