p1-insta485-static

Windows Command line tools (WSL)

The Windows Subsystem for Linux (WSL) runs an Ubuntu Linux guest virtual machine on your Windows host machine.

Update Windows

We strongly recommend Windows 11, which supports Linux-based GUI applications. An example is debugging an end-to-end web site test by viewing how the test programmatically clicks links in a browser.

At a minimum, you need Windows 10 version 2004, Build 19041 or higher. We recommended Windows 11 version 22H2 Build 22621 or higher. Instructions for how to check your Windows version.

Free Windows upgrades are available for UM students via OnTheHub.

Install WSL

Follow the instructions from Microsoft to install WSL 2. If you have not set up WSL before, follow all instructions and choose the latest version of Ubuntu for your Linux distribution. If you already have an older version of Ubuntu installed, go to the Upgrade version from WSL 1 to WSL 2 section. Ubuntu 22.04 or newer is required.

We require WSL 2. Some software requires WSL 2 to work correctly, for example end-to-end testing of a client-side dynamic pages app using a headless browser. If you cannot update to WSL 2 and you have confirmed your Windows Version is correct, try downloading the WSL 2 Linux Kernel and updating it manually. You can find instructions from Microsoft here.

Start a Windows PowerShell. Verify that you are using WSL 2.

$ wsl -l -v
  NAME                   STATE           VERSION
*  Ubuntu-22.04           Running         2

Open terminal

Start a Bash shell (not a Windows PowerShell).

ubuntu shell in windows search bar results

An Ubuntu Bash shell is a terminal that looks like this:

screenshot of an ubuntu bash shell

Install CLI tools

You can now use Ubuntu Linux tools, including the apt package manager.

$ sudo apt update
$ sudo apt install python3 python3-pip python3-venv python3-wheel python3-setuptools git tree default-jre

Pro-tips

Copy paste

Enable “Use Ctrl+Shift+C/V Copy/Paste” option in the Console “Options” properties page (Source: Microsoft blog).

Accessing Windows files

Windows files are accessible from Linux at /mnt/c/. You have a separate Ubuntu home directory, e.g., /home/awdeorio/.

$ cd /mnt/c/Users/awdeorio/Desktop    # Windows Desktop
$ cd /mnt/c/Users/awdeorio/Documents  # Windows Documents

CLI open file

Simulate a double-click from the command line in the WSL Bash shell.

$ wslview babychickens.jpg

Pitfalls

Avoid these common WSL pitfalls.

Spaces in path

Avoid spaces in any part of your project directory path. Some Linux programs do not support spaces in file paths.

Bad Example Good Example
/home/awdeorio/src/EECS 485/p1-insta485-static /home/awdeorio/src/eecs485/p1-insta485-static

Network file share

Avoid project directories starting with /mnt/c/. A directory shared between Windows and Linux (/mnt/c/whatever/) can cause massive slowdowns because WSL uses a network file share to communicate the files between Windows and Linux.

Instead, put your projects somewhere in your Linux home directory (/home/awdeorio). Sub directories are fine.

Bad Example Good Example
/mnt/c/Users/awdeorio/src/eecs485/p1-insta485-static /home/awdeorio/src/eecs485/p1-insta485-static

Root user

Avoid doing everyday coding as the root user in WSL. Some programs don’t work correctly when run as root. When you first installed Ubuntu, you should have been prompted to create a Linux username and password.

Bad example: If the default is a root login, here’s how to change your linux username and password. For the same reasons, avoid using su or su root.

# whoami
root

Good example: When you start a Bash shell (not a Windows PowerShell), you should have a non-root username.

$ whoami
awdeorio

Acknowledgments

Original document written by Andrew DeOrio awdeorio@umich.edu.

This document is licensed under a Creative Commons Attribution-NonCommercial 4.0 License. You’re free to copy and share this document, but not to sell it. You may not share source code provided with this document.