Install GCC/Clang & VS Code

C · Lesson 2 of 32 8 min read Updated

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:

CompilerWhat you get
GCC 13Most C23 features (nullptr, constexpr, bool keywords), using the option -std=c2x
GCC 14Accepts the option name -std=c23
GCC 15 and newerUses C23 by default and adds #embed
Clang 19 and newerSupports 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.

  1. Download the installer from the official site, msys2.org, and run it. Keep the default folder C:\msys64.
  2. When the installer finishes, a terminal window for the UCRT64 environment opens. If it does not, open "MSYS2 UCRT64" from the Start menu.
  3. Install GCC, the gdb debugger and make with the command below. Press Enter to accept all packages, then Y to confirm.
  4. Add the folder C:\msys64\ucrt64\bin to your Windows Path: search Start for "Edit environment variables for your account", select Path, click Edit, then New, paste the folder and click OK.
  5. Close every terminal, open a new PowerShell window and check the versions.
Terminal
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
PowerShell
gcc --version
gdb --version

If 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:

PowerShell
wsl --install

Restart 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:

Terminal
sudo apt update
sudo apt install build-essential gdb
sudo apt install clang
gcc --version

On 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:

Terminal
xcode-select --install
clang --version

A 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.

  1. Install VS Code from code.visualstudio.com.
  2. Open the Extensions view (Ctrl+Shift+X, or Cmd+Shift+X on a Mac), search for "C/C++" and install the extension by Microsoft (its ID is ms-vscode.cpptools). It adds code completion, error underlines and debugging support.
  3. Create a folder for your C practice, for example c-practice, and open it with File, Open Folder.
  4. Open the Command Palette (Ctrl+Shift+P), run "C/C++: Edit Configurations (UI)", set Compiler path to your gcc or clang, and set C standard to c23.
  5. 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:

C
#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:

Terminal
gcc -std=c23 -Wall -Wextra hello.c -o hello
./hello
Output
My 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 Path change only reaches terminals opened after it. Close VS Code and every terminal, then open them again. Also check that the folder C:\msys64\ucrt64\bin really contains gcc.exe.
  • Installing the wrong MSYS2 package. Typing pacman -S gcc installs a GCC for the MSYS environment, whose programs depend on extra MSYS files. Use the mingw-w64-ucrt-x86_64-... packages shown above.
  • Typing hello instead of ./hello on 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-essential and gdb; on macOS run xcode-select --install to get Clang.
  • Install VS Code with Microsoft's C/C++ extension and compile from its built-in terminal.
  • Always compile with -std=c23 -Wall -Wextra so 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
C
#include <stdio.h>

int main(void)
{
    printf("Name: Ananya Sharma\n");
    printf("City: Lucknow\n");
    return 0;
}
Output
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)?

2. What does the gcc command run on a Mac with Apple's Command Line Tools?

3. Why should you pass -std=c23 when you compile?

4. On Ubuntu, which package installs GCC, make and the C library headers in one step?

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