In this workflow, you write hello.c in VS Code, but the project lives inside WSL Ubuntu. gcc runs inside WSL and turns hello.c into an executable file named hello. The WSL terminal then runs that executable with ./hello.

The important distinction is that VS Code edits the file, WSL provides the Linux environment, gcc compiles the program, and the .c file itself does not run.

Minimal Prerequisites

This workflow assumes WSL Ubuntu and VS Code are already installed. It focuses on the first C compile-and-run path, not on installing WSL itself.

You need:

  • WSL Ubuntu installed.
  • VS Code installed on Windows.
  • VS Code able to open WSL folders, usually through the WSL or Remote - WSL extension.
  • Compiler tools installed inside WSL Ubuntu.

Check whether gcc is available inside the WSL terminal:

gcc --version

If the command is not found, install the common Ubuntu build tools inside WSL:

sudo apt update
sudo apt install build-essential

The installation happens inside WSL Ubuntu. A compiler installed only on Windows is not automatically available in the WSL terminal.

Create a WSL Project Folder

Open the WSL Ubuntu terminal, then create and enter a project folder:

mkdir -p ~/code/hello-c
cd ~/code/hello-c

mkdir -p ~/code/hello-c creates the folder. The -p option also creates parent folders if needed and does not fail if the folder already exists.

cd ~/code/hello-c moves the terminal into that folder. Later commands will use this current directory as their starting point.

For this first workflow, keep the project under ~/code/hello-c inside WSL. That path means something like:

/home/yourname/code/hello-c

It is not the same as:

C:\Users\yourname\code\hello-c

WSL can access Windows files, and Windows can access WSL files, but mixing paths makes the first compile-and-run path harder to understand.

Open the Folder in VS Code

From the same WSL terminal, while inside the project folder, run:

code .

code starts VS Code from the terminal. The . means the current directory. Because the command is run from the WSL terminal while the current directory is ~/code/hello-c, VS Code opens that WSL folder.

When this works correctly, VS Code should indicate that it is connected to WSL, often with wording such as WSL: Ubuntu.

Create hello.c

In VS Code, create a file named hello.c in the opened folder.

Put this code inside it:

#include <stdio.h>
 
int main(void) {
    printf("Hello, WSL C!\n");
    return 0;
}

Save the file.

At this point, hello.c is source code. It is text written in the C language. It is not the executable program yet.

Compile the Program

Open the VS Code integrated terminal and make sure it is a WSL terminal, not PowerShell. A WSL terminal shows Linux-style paths such as ~/code/hello-c or /home/yourname/code/hello-c.

Run:

gcc hello.c -o hello

gcc is the compiler. hello.c is the input source file. -o hello tells gcc to name the output executable hello.

If there is no error message, compilation succeeded. The folder now contains two different files:

hello.c   source code written by you
hello     executable file produced by gcc

For this first program, gcc hello.c -o hello hides several toolchain steps, but the useful beginner boundary is simple: source file in, executable file out.

Run the Program

Run the executable from the WSL terminal:

./hello

Expected output:

Hello, WSL C!

./hello means “run the file named hello in the current directory.”

The ./ matters because Linux shells do not automatically search the current directory for programs. Typing hello asks the shell to search its configured command paths for a command named hello. Typing ./hello explicitly points to the executable file in the current folder.

Common Failures

If gcc is not found, install compiler tools inside WSL:

sudo apt update
sudo apt install build-essential

If code . is not found, VS Code’s terminal command or WSL integration is not available from the WSL shell yet. Check that VS Code is installed on Windows and that the WSL extension is available.

If the VS Code terminal opens as PowerShell, switch it to a WSL terminal before compiling and running this example.

If hello: command not found appears, run the executable as:

./hello

If No such file or directory appears, check the current folder and file names:

pwd
ls

pwd shows where the terminal is. ls shows which files are in the current folder.

If running gcc hello.c created a.out, that is the default output name. Run it with:

./a.out

Or compile again with an explicit output name:

gcc hello.c -o hello
./hello

Core Takeaway

A first C program in WSL is not run from the .c file.

The workflow is:

write source code in VS Code
compile it with gcc inside WSL
run the produced Linux executable from the WSL terminal

For this example:

hello.c -> gcc -> hello -> ./hello