Set Up C Like a Professional in 15 Minutes (WSL + VS Code)
There are 4 ways to set up C on your laptop In this article, we’ll focus on WSL with VS Code.
Why WSL? A real Linux system inside Windows, the best C tools in one command, and the same setup professionals use.
Step 1: Install WSL
- Press the Windows key, type PowerShell, right-click it, and choose Run as administrator.
2. Run:
wsl --install- The above command only works if WSL is not installed at all
wsl --installdoesn't work? You can turn on WSL manually. Press the Windows key, type Turn Windows features on or off, and open it. Tick Windows Subsystem for Linux and Virtual Machine Platform, click OK, and restart your computer. Then runwsl --installagain.
3. Restart your computer when asked.
4. After the restart, an Ubuntu window usually opens by itself. Wait a minute for it to finish. If it doesn’t open, press the Windows key, type Ubuntu, and click the app.
5. Create a username (lowercase letters, no spaces) and a password. You’ll need this password later, so remember it. When you type the password, nothing shows on screen. That’s normal. Just type it, press Enter, then type it again to confirm.
6. Check that WSL is installed
In the Ubuntu window, type this and press Enter:
wsl.exe --list --verboseYou should see something like this:
Step 2: Install the C Compiler
WSL is ready, but it doesn’t have a C compiler yet. A compiler turns the C code you write into a program the computer can run. Let’s install one.
- In the Ubuntu window, type this and press Enter:
sudo apt update- Enter your password if asked. (It won’t show as you type. That’s normal.)
2. Then type this and press Enter:
sudo apt install build-essential gdbWhat does this install? Three tools that every C programmer uses:
- GCC: turns your C code into a program (the compiler)
- Make: builds bigger projects with one command
- GDB: helps you find bugs (the debugger)
Press Y and Enter when asked to continue. This takes a few minutes.
3. When it finishes, check that the compiler works:
gcc --versionStep 3: Install VS Code
What is VS Code? VS Code is a free code editor from Microsoft. It’s where you’ll write your C code. Download it from official website and install it with the default options.
Already have VS Code? Skip to the extensions in step 4.
Step 4: Install the Extensions
Extensions are small add-ons that give VS Code extra abilities. We need two.
- Open VS Code.
- Click the Extensions icon on the left side (the four squares), or press Ctrl + Shift + X.
- In the search box, type WSL, find WSL (by Microsoft), and click Install.
This lets VS Code connect to your Ubuntu.
- Search for C/C++, find C/C++ (by Microsoft), and click Install.
This adds code coloring, suggestions, and debugging for C.
Step 5: Open Your Project in VS Code
There are two ways to open VS Code connected to Ubuntu. Pick whichever you prefer.
Get Dineth nimnaka’s stories in your inbox
Join Medium for free to get updates from this writer.
Method 1: Open it from the Ubuntu window (recommended)
In the Ubuntu window, type these commands one by one and press Enter after each:
cd ~
mkdir c-projects
cd c-projects
code .What each command does:
cd ~goes to your home folder in Ubuntu, so your project lives on the Linux side.mkdir c-projectsmakes a new folder calledc-projects. (mkdirmeans "make directory".)cd c-projectsmoves you into that folder.code .opens the current folder in VS Code. The.means "this folder".
“Installing VS Code Server… Downloading”? This is normal. The first time you run code ., VS Code installs a small helper inside Ubuntu so it can connect to Linux. It only happens once.
Wait for it to reach 100% and VS Code will open by itself.
Method 2: Open VS Code yourself
- Open VS Code from the Start menu.
- Click the
><icon in the bottom-left corner.
- Choose Connect to WSL using Distro…
then pick Ubuntu.
Once the download reaches 100%, VS Code opens by itself.
In the new window, click File → Open Folder…
In the box, you’ll see your home folder, /home/yourname/. After it, type a name for your new folder, for example /home/yourname/my-first-c.
Here, I’m creating a folder named C-Files. All my C programs will live in it.
C-Files folder and WSL: Ubuntu in the bottom-left corner.Step 6: Write Your First C Program
By now, you’ve opened VS Code using one of the two methods above: from the Ubuntu window (Method 1) or by connecting to WSL yourself (Method 2). You can use whichever method you like. Both give the same result.
Your folder is open and VS Code is connected to Ubuntu (check that the bottom-left corner says WSL: Ubuntu). Now let’s create your first C file. This works the same whichever method you used to open the folder.
- In the Explorer panel on the left, move your mouse over the folder name (C-Files). Click the New File icon (a page with a plus sign).
- Type the file name
hello.cand press Enter. - Type this code into the file:
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}4. Press Ctrl + S to save.
Step 7: Compile and Run
- Open the terminal inside VS Code yourname@computer:~/C-Files$`.
- Compile your program:
gcc hello.c -o hello3. Run it:
./helloYou just compiled and ran your first C program.








