This only works if you are using a windows machine. If you are not using a windows machine, then you should use docker, or one of the other setup options.

WSL Install Command

The first step to installing WSL is to open powershell (or windows command prompt) in adminstrator mode.

To do this hit the windows key on your keyboard (should be near the lower left of your keyboard) and it should let you start typing into a search bar. type in “powershell” and then once power shell shows up as a result, right click it and select “run as administrator”

powershell_search

powershell_admin

Once you have powershell open in admin mode, you can type in the following command:

wsl --install -d Ubuntu-22.04

It may take a couple minutes for this command to run and it may require you to restart your computer (it will tell you if a restart is necessary).

Setting up your UNIX account

Once you have done the previous step, you should be able to run an application called “Ubuntu on Windows” or it may even start running it for you. If it does not launch for you, you can open it similar to how we launched powershell but without administrator mode. (hit windows key then start typing in “Ubuntu” and then select it. You do not have to do it in administrator mode though).

Once you boot it up, it will probably show something like:

Installing, this may take a few minutes...

After a few minutes, it should then further print:

INstallation successful!
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:

From here, type whatever user name you want. Ubuntu may only accept usernames that:

  • start with a lowercase letter
  • can only contain lowercase letters, digits, underscores (e.g. _) and dashes (e.g. -)

After you type in a user name and hit enter, you will have to set a password. NOTE: when you type in the password, nothing will show on the screen. This is normal, it is just doing this so that people reading your screen cannot see the password you type. If you make a mistake while typing out the password, just hold the backspace button for a while to “clear” whatever you typed and then type it again.

Password FAQs

  • Q: I want to change my UNIX password, but I know it already. What do I do?
    • You can log in to your ubunutu terminal and type in the command passwd which will ask for your current password before allowing you to reset.
  • Q: I forgot my UNIX password! What can I do?
    • Open powerhsell in administrator mode and type wsl -u root
    • use the command passwd <username> where <username> is your UNIX account username and it should allow you to change your UNIX account password.

Installing Required Packages

Once you are in your ubuntu terminal, you should run the following command to check for any updates and apply them:

apt-get update && apt-get upgrade

if you are trying to copy-paste commands in the terminal, then you cannot use CTRL + C and CTRL + V as normal. Instead you just need to right click. Right clicking while you have any text selected in the terminal copies that text, and if you right click without any text selected, it will paste. To be clear: you can CTRL + C to copy something outside of the terminal and then to paste it in the terminal just right click.

From here you then need to run these commands to get everything setup as needed: Note: these are four different commands. Run them one at a time.

curl -o env-setup.sh https://www.cis.upenn.edu/~cis5480/current/setup/env-setup.sh 
curl -o settings.json https://www.cis.upenn.edu/~cis5480/current/setup/settings.json
chmod +x env-setup.sh
sudo ./env-setup.sh

From here you can delete the setup files as so:

rm env-setup.sh
rm settings.json

Accessing Files

Now you have linux on your windows machine! Notably though, you sort of have two separate file systems, your linux one and your windows one. You can access files from one in the other, but you should only really do this when you want to move or copy a file from one place to another.

Here are some commands you may find useful though:

  • If you want to access the files in your WSL file system through file explorer, you can type explorer.exe . to open the current directory in the file explorer.
  • If you want to copy a file from your windows file system into WSL you can run a command to do that. Lets say I wanted to copy a file in my Downloads folder named scratch.c with the path: C:\Users\tqmcgaha\Documents\scratch.c I could copy it to WSL by doing cp /mnt/c/Users/tqmcgaha/Documents/scratch.c . (hopefully you can notice the pattern between the windows path and the wsl command).

Other Useful Tools:

Windows Terminal

Windows Terminal is a useful tool that can provide a nicer expereince for using WSL. Notably it allows you to have mulitple tabs (default only allows multiple windows) and greater customization of your terminal. We won’t go into detail here, but setup instructions can be found here

Using vim with WSL

using vim in WSL is not any different than using it for other environments, we direct you to the vim guide to see more.

Using VS Code with WSL

If you haven’t already, you need to first install Visual Studio Code on your host computer.

Start a new VSCode window, and follow these steps to install the WSL plugin:

  1. Click into Extensions tab on the left vertical bar of your VSCode window. It is usually the fifth from the top down.
  2. In the search bar, type in “WSL”.
  3. Usually the first option that came up is the one we want, click into it.
  4. Make sure it is the extension WSL we are looking for. Click the Install button.

wsl_extension

Once you have that there are two ways to open a project in VS Code

To open a project from WSL all you have to do is type in the command code .

To open a project from VS code, you can just hit F1 and select the option WSL: Connect to WSL

Let’s try running the code we pulled from our repo to make sure it works. In the exlporer section on the left click on the repo folder to expand it. Inside you should see the check_setup folder. Click on check_setup to expand it and see the files in it. You should be able to see the file hello.c and a file called Makefile.

If you click on the hello.c program to view it, you can see that it just prints things out and exists to verify that your setup worked. To further test our code, lets try to compile and run it.

In the terminal type cd 26fa-cis5480-xyz and then cd check_setup to move the terminal’s current directory to the check_setup directory inside of your repo.

Once you have done this, you can try running the command make which should compile hello.c into a program called hello. Try running the program by doing ./hello in the terminal and you should be able to see the message it prints!

{. :warning }

If you get an error when you try to run make, try running the following commands one after the other:

apt-get install -y lsb-release
apt-get install -y gnupg
apt-get install -y software-properties-common
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 19
rm llvm.sh