Install C and VS Code
Read · 1 of 9
What you're installing
Two things: VS Code, the editor where you write code, and a C compiler (gcc), the tool that turns your code into a program the computer can run.
No laptop handy? Skip this module: every lesson here runs in your browser. You'll need it before the lab exam, though.
Read this lesson as text
Everything you need to write and run C on your own computer.
What you're installing
Two things: VS Code, the editor where you write code, and a C compiler (gcc), the tool that turns your code into a program the computer can run.
No laptop handy? Skip this module: every lesson here runs in your browser. You'll need it before the lab exam, though.
1. Install VS Code (Windows)
Download the Windows installer and run it.
On the Select additional tasks screen, tick Add to PATH.
2. Install MSYS2 (Windows)
MSYS2 is the easiest way to get an up-to-date gcc on Windows.
Run the installer and keep the default folder, C:\msys64.
3. Install the compiler (Windows)
Open MSYS2 UCRT64 from the Start menu, paste this command and press Enter.
Press Enter again to accept the defaults, then Y to confirm.
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
4. Tell Windows where gcc is (Windows)
Search the Start menu for Edit environment variables for your account and open it.
Select Path, click Edit, then New, and paste the folder below. Click OK on every window.
C:\msys64\ucrt64\bin
5. Check it worked (Windows)
Open a new Command Prompt (windows opened before step 4 can't see the change), run this, and paste what it prints.
gcc --version
1. Install VS Code (macOS)
Download VS Code for Mac, open the download and drag Visual Studio Code into Applications.
2. Install the compiler (macOS)
Open Terminal (⌘ Space, type Terminal), paste this and press Enter.
A window pops up: click Install and wait for it to finish.
xcode-select --install
3. Check it worked (macOS)
Run this and paste what it prints. On a Mac it says Apple clang, which is perfect.
gcc --version
1. Install VS Code (Linux)
Download the .deb package (Ubuntu, Debian) and open it, or install it from your software centre.
2. Install the compiler (Linux)
Open a terminal, paste this and press Enter. It asks for your password.
sudo apt update && sudo apt install -y build-essential gdb
3. Check it worked (Linux)
Run this and paste what it prints.
gcc --version
Add C support to VS Code
In VS Code, open Extensions (Ctrl+Shift+X, ⌘⇧X on Mac).
Search for C/C++, pick the one by Microsoft, and click Install.
Run your first program
Make a folder called c-lab and open it with File → Open Folder.
Create hello.c, paste the code below and save.
Open Terminal → New Terminal and run the command. If it prints Hello from my computer!, you're ready.
#include <stdio.h>
int main() {
printf("Hello from my computer!\n");
return 0;
}gcc hello.c -o hello && ./hello
On Windows, run it like this (Windows)
The Windows terminal runs programs slightly differently. Use this instead:
gcc hello.c -o hello; .\hello.exe