This guide was tested on a new installation of Windows 11 on January 5th 2025.
EECS280 Foundation
This guide is built on the EECS280 Windows VSCode Setup Tutorial. WSL and VSCode is installed via the written method below, but the rest is based on their guide.
The following changes were made for EECS281:
- Different WSL installation method
- Use EECS281 Makefile instead of EECS280 Makefile
- Use EECS281 Project 0 instead of EECS280 Project 1
Video Tutorial
Our video walkthrough contains the aforementioned changes, and is the recommended approach.
At a certain point in the video, there will be a command containing apt used to update dependencies. Unfortunately, the command used in the video is out of date. When it’s time to run the command, use this instead:
sudo apt update && sudo apt install g++ make rsync wget git ssh gdb python3 tree
You can click here to watch the tutorial video.
If you already have a working VS Code setup using the C/C++ extension, you can skip to 11:35.
Alternative Written Tutorial
If you don’t want to watch the video, and would instead prefer a fully written version, you can follow the linked EECS280 tutorial without the aforementioned changes, and then follow their EECS281 Project Setup Tutorial.
Visual Studio Code on Windows Subsystem for Linux
Visual Studio Code (VS Code) is a free code editor for Windows, Mac, and Linux operating systems. VS Code is not a traditional integrated development environment (IDE) because it has no integrated code compilation abilities. As a result, terminal commands play a larger role in VS Code’s workflow. Using VS Code for EECS 281 will help you familiarize yourself with Linux terminal commands and Makefiles. You’ll also find VS Code very useful in other EECS courses at Michigan. This guide is tailored specifically for EECS 281 students interested in running VS Code on Windows Subsystem for Linux (WSL). This guide will explain how to install WSL, how to install and configure VS Code for WSL, how to compile and run an EECS 281-style program, and how to use VS Code’s visual debugger. Let’s get started!
Introduction to WSL
WSL is a feature in Windows 10+ that allows you to use Linux command-line tools and applications alongside Windows without the hassle of a virtual machine or dual boot setup. WSL typically requires fewer resources than a virtual machine and still allows you to access your Windows file system from within WSL. However, WSL does not natively support graphical programs and only provides limited support for programs that attempt to access hardware. For more information about WSL, please see the “Resources” page at the end of the document.
For this guide, we will use WSL 2 (which we will refer to as just “WSL”). WSL 2 is a newer version of WSL designed with better file system performance in mind. WSL 2 uses a lightweight virtual machine to run Linux. This virtual machine operates entirely behind the scenes and requires no configuration by the user. WSL 2 is faster than WSL except when accessing the Windows file system from within WSL or when accessing the WSL file system from within Windows. WSL 2 is also only compatible with certain builds and versions of Windows 10+, so you make sure your computer is up-to-date before beginning. If you download updates, make sure to apply them and restart before beginning.
How to Install WSL
To install WSL, open PowerShell as administrator and run the following command.
wsl --install
If this command gives you an error about wsl not being recognized, follow Microsoft’s manual installation instructions. Pay careful attention and read all the content of each step, as some steps can be easy to miss. When you get to selecting a distribution, choose Ubuntu.
After you’re done installing WSL, make sure to restart your computer. The setup process will not work if you do not restart your computer after installing WSL.
Setting up Ubuntu
Ubuntu can be launched by searching for “Ubuntu” in the search bar at the bottom of your screen and clicking on the application that appears in the results. When first launched, Ubuntu will go through a one-time setup process, which we detail below.
If you receive an error about virtualization not being enabled, you’ll have to change a setting in your computer’s BIOS. To do this, lookup how to enable virtualization in <Name of computer> bios, for example: how to enable virtualization in msi katana 15 bios.
Once you do this, try to launch Ubuntu again. If you get the same error again, make a post on the class discussion board. Make sure you include which computer you have.
When prompted, enter a username and password. The username and password do not need to be the same as your Windows username and password. The username and password are important for navigating your WSL file system and running Linux command-line tools, so don’t forget them! For the rest of this guide, your WSL username will be referred to as USER, and your WSL password will be referred to as PASSWORD. Your Windows username will be referred to as WINUSER.
Once you’ve finished the Ubuntu setup, it will place you into a shell (place where you enter commands). You can either close it, or keep it open and follow the “How to use Ubuntu” section below.
How to use Ubuntu
After Ubuntu has completed its one-time installation, you can launch it with the same method as above, or by running the following command:
bash
When you launch Ubuntu, you will start at the following directory.
/home/USER
This directory is located within the WSL file system. If you choose to uninstall WSL, all files within the WSL file system, including all files at this directory, will be deleted. If you wish to access your Windows file system from within Ubuntu, you can change directories by running the following command.
cd /mnt/c/Users/WINUSER
To return to your WSL file system, you can run the following command.
cd ~
Doing so will bring you back to your home directory.
/home/USER
For an introduction to the Linux command line, please see the “Resources” page at the end of the document. To run sudo commands, you’ll need to enter your PASSWORD when prompted.
At this point, you should have successfully installed WSL on your computer. The next step is to install VS Code.
How to Install VS Code
VS Code can be downloaded at https://code.visualstudio.com/download. Click the big, blue button beneath the Windows logo to download an executable. Run the executable to install VS Code for Windows. You can launch VS Code by using the search bar at the bottom of your screen. Launching VS Code for the first time will open a window similar to the one pictured below.
Click the blue “Welcome” link, and it should place you in a window similar to the one pictured below. Your “Recent” files, your tabs in the “Explorer” interface, and your icons in the sidebar on the left may look different.
VS Code is extremely customizable. If you don’t like a feature, you can probably find a way to disable it by searching on Google.
Introduction to VS Code
You can navigate VS Code using the sidebar on the left.
Downloading the WSL extension
Before you start programming, you’ll need to download the WSL extension. The WSL extension allows you to use VS Code in WSL just as you would from Windows.
If VS Code detects that you have WSL enabled and installed on your computer, it may prompt you automatically to install the extension. You may choose to install this extension from the prompt if you’d like. If you do not receive this prompt or wish to install the extension manually, you’ll need to search the extension marketplace instead.
If you are following this guide and re-installed VS Code after having uninstalled it, you may find that searching the extension marketplace results in an error stating that you cannot connect to the marketplace at this time. To resolve this error, you may need to uninstall VS Code and navigate to the following folder within your Windows file system.
/mnt/c/Users/WINUSER/AppData/Roaming/CodeDelete the “Code” folder within “Roaming” and re-install VS Code. VS Code retains some files between multiple installations if not handled properly. Failure to clean up these files between installations may cause problems, such as being unable to access the extension marketplace.
Go to the extension marketplace and use the search bar to search for “WSL”. Find the “WSL” extension within the search results and click on it. You should be brought to the page shown below. Click the install button.
When finished, close VS Code.
Open VS Code in WSL
You should configure VS Code before you begin programming. We’re about to reopen VS Code. This time, however, we’ll reopen VS Code inside our WSL file system. There are two ways to complete this task.
Option 1
Open your Ubuntu terminal. By default, you’ll start at the following directory.
/home/USER
This directory resides within your WSL file system. In this directory, run the command
code .
The above command consists of the word “code” followed by a space and then a dot. Running this command will launch VS Code in your current working directory. In this case, your current working directory is /home/USER. VS Code should now be running within your WSL file system. In the bottom-left corner of your VS Code window, you should see a blue box that indicates VS Code is running in WSL. The blue box should also display which Linux distribution you’re using (in our case, Ubuntu).
VS Code now has access to your WSL file system, and the files in your current working directory will appear in the file explorer interface. If you launched VS Code from inside the directory
/home/USER
then you may see some hidden files in the file explorer interface prefixed with a .. We’ll come back to our file system later when we begin programming. First, we have to configure VS Code.
Option 2
Launch VS Code by using the search bar at the bottom of your screen. Launching VS Code should open a window similar to the one pictured below.
Take a look at the blue box in the bottom-left corner of the VS Code window. If it already says WSL, you’re done. If it doesn’t, click it. Doing so should open a drop-down menu with a search bar as shown below.
Choose the option “Connect to WSL”. Doing so will launch VS Code inside your WSL filesystem as shown below. In the bottom-left corner of your VS Code window, the blue box should now indicate that VS Code is running in WSL. The blue box should also display which Linux distribution you’re using (in our case, Ubuntu). VS Code now has access to your WSL filesystem.
Similarly to before, click the blue “Welcome” link.
To access a particular directory in VS Code, click on the blue “Open Folder” button. Doing so will open a menu in which you can select a particular directory inside your WSL file system to open within VS Code. Once you’ve chosen a directory, the files in that directory will appear in the file explorer interface. For now, it is sufficient to open the directory /home/USER as shown below.
You may see some hidden files in the file explorer interface with the prefix .. We’ll come back to our file system later when we begin programming. First, we have some extensions to install!
Warning on using the Windows file system
It may be tempting to use VS Code inside your Windows file system to avoid the hassle of moving tarballs between your Windows file system and your WSL file system. Do not use VS Code inside your Windows file system. Whenever you’re programming with VS Code, you should be working inside your WSL file system. In other words, whenever you’re programming with VS Code, the blue box in the bottom-left corner of your VS Code window should read “WSL” followed by your Linux distribution of choice. The only time you should be using VS Code inside your Windows file system is to open VS Code inside your WSL file system.
While the hassle of moving tarballs between your Windows file system and your WSL file system may seem inconvenient, it is far better than the alternative. Using VS Code inside your Windows file system may cause esoteric and difficult-to-diagnose bugs to appear. Please do not use VS Code inside your Windows file system.
Common Mistake
Make sure you open EECS281 VS Code projects in WSL, not just in Windows. You may accidentally open a project in just Windows if you launch VS Code from the start menu. If you’ve launched VS Code from the start menu and are unsure if you’ve made this mistake, follow option 2 of “Open VS Code in WSL”.
Resources
What is the Windows Subsystem for Linux?
Frequently Asked Questions about Windows Subsystem for Linux
Windows Subsystem for Linux Installation Guide for Windows 10