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 build 19044+ 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

Update WSL

Even if you have Windows 11 or a high enough version of Windows 10, you still need to update WSL 2 in order to use Linux-based GUI applications.

In Windows PowerShell, run these commands:

$ wsl --update
$ wsl --shutdown

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

Test a GUI app

To verify that you can successfully run GUI apps on Ubuntu, install x11-apps and run a small GUI app called xeyes.

$ sudo apt-get install x11-apps
$ xeyes

You should see a new window open with a pair of eyes that follow your cursor.

If it doesn’t work, you may need to update WSL. If you’ve run both wsl --update and wsl --shutdown but it’s still not working, run this:

$ sed -i 's/^export DISPLAY=.*$//g' ~/.bashrc
$ source ~/.bashrc

The first command will remove any lines from your bash config file that start with export DISPLAY=. If you had any such lines, they would have interfered with WSL’s ability to forward GUI apps from Linux to Windows. The second command reloads your bash config file.

Then try running xeyes again.

As a last resort, you can try a fresh install of Ubuntu by running the following commands in Windows PowerShell. This will delete everything in your WSL filesystem!!! Please make sure to back up any important files you have in Ubuntu first. You can copy files on your Linux file system to your normal Windows file system by using the cp command with a Windows directory. (The EECS 280 tutorial shows another option.)

$ wsl --unregister ubuntu
$ wsl --install ubuntu


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


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

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

$ whoami


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.