Computer Science

Installing Windows Subsystem for Linux (WSL)

UNIX, Linux, and Posix

When interacting with other computers over a network, it is increasingly important for one to be familiar with UNIX/Linux ("*NIX") operating systems. In this class, our course server is running on a Linux system, and people using an Apple macOS computer are running a variant of UNIX. When these people launch a Terminal window, they issue commands in that interface that follow the POSIX protocol.

What about Windows?

The Command Prompt application in Windows is similar to a Terminal, but doesn't use the same POSIX standards. (The POSIX command for listing the files in a directory is ls, for example, while the Windows command is dir.) Windows does allow one to install and use a POSIX-compliant Terminal window that runs in the "Windows Subsystem for Linux."

Here's how to enable/install WSL.

Installing the Windows Subsystem for Linux

  1. Enable Developer Mode
    From the menu bar's Search function look for "developers", and then click on the "Developer Mode" button, and agree to the warning.
  2. Enable Linux subsystem
    From the menu bar's Search function look for "control panel." Under Programs > Programs and Features > Turn Windows features on and off... find Windows subsystem for Linux and check that box, then click Okay. You'll need to restart the computer for that installation to take effect.
  3. Install Ubuntu
    From the menu bar's Search function look for "Ubuntu", then click "Install app." After Ubuntu is downloaded and installed, you'll be asked to create a username and password, which can be different from your regular Windows username and password. Note that when you type in the password in the terminal window, nothing will be echoed on screen, not even dots or asterisks. This behavior is normal.
  4. Launch a Terminal window
    You can now launch a Terminal window by typing "bash" or "ubuntu" into the Menu Bar's Search field.

Congratulations! Your Windows machine is now POSIX compliant!

Reconciling your two home directories

The Ubuntu/Linux/bash subsystem that you've installed runs under a username that is not connected to your regular Window's system. The home directory on your Ubuntu system is not the same as the home directory on Windows.

If you want to use bash to access your Windows directory, you'll need to issue a command like this into the terminal when it launches:

$ cd "/mnt/c/Users/Richard White/"

From here you'll be able to find your Windows files without difficulty.

If you decide you'd like to have your home directory in bash actually be the home directory in Windows, you can:

  1. In a new terminal session (in your Ubuntu home directory) type nano .bashrc. This will allow you to edit that file and have it re-direct your home directory.
  2. At the end of that file, including the following two lines.
    HOME="/mnt/c/Users/Richard White" cd ~
    Use your own username rather than Richard White, of course.
  3. Close the current Terminal window and open a new one. You should find yourself redirected to your Windows home directory, and you can proceed accordingly.