WSL

Setup WSL for your Windows

The first and most important part of setting up your Windows dev environment is installing the Windows Subsystem for Linux (WSL). I recommend sticking with Ubuntu, but feel free to try out as many distributions as you like. There are no issues with having multiple distributions installed at once.

Installing WSL 2

WSL 2 is the latest version of WSL, adding new features like a full Linux kernel and full system call compatibility. There used to be a handful of steps needed to install it, but we now only need to enter the following command into PowerShell or Command Prompt:

wsl --install

This command does the following:

  • Enables the optional WSL and Virtual Machine Platform components
  • Downloads and installs the latest Linux kernel
  • Sets WSL 2 as the default
  • Downloads and installs the Ubuntu Linux distribution (a reboot may be required)

Using the --install command defaults to Ubuntu and only works if WSL is not installed yet. If you would like to change your default Linux distribution, follow these docs.

User Config

Once the process of installing your Linux distribution with WSL is complete, open the distribution (Ubuntu by default) using the Start menu. You will be asked to create a User Name and Password for your Linux distribution. When you enter your new password, nothing will display in the terminal. Your keyboard is still working! It is just a security feature.

  • This User Name and Password is specific to each separate Linux distribution that you install and has no bearing on your Windows user name.
  • Once you create a User Name and Password, the account will be your default user for the distribution and automatically sign-in on launch.
  • This account will be considered the Linux administrator, with the ability to run sudo (Super User Do) administrative commands.
  • Each Linux distribution running on WSL has its own Linux user accounts and passwords. You will have to configure a Linux user account every time you add a distribution, reinstall, or reset.

Updating Linux

It is recommended that you regularly update and upgrade your packages. In Ubuntu or Debian, we use the apt package manager:

sudo apt update && sudo apt upgrade

Windows does not automatically update or upgrade your Linux distribution(s). This is a task that most Linux users prefer to control themselves.

Mapping Your Linux Drive

When you open the Windows file explorer, it displays your devices and drives. We are going to add our Ubuntu virtual drive as a network location for easy access.

  1. Open the \\wsl$\ location from file explorer:

  1. Right-click on the Ubuntu folder, and select Map network drive:

  1. Select the drive letter you would like to use, leave Reconnect at sign-in checked and Connect using different credentials unchecked, and then click finish (mine will look slightly different because it's already been done):

  1. The end result should look something like this:

If you wanted to access your Windows files from the Linux terminal, they are found in the /mnt/ directory, so your Windows user directory would be located at /mnt/c/Users/username.

With your Ubuntu drive mapped, you can easily drag/drop or copy/paste Windows files to the Linux file system by using the file explorer.

However, it is recommended to store your project files on the Linux file system. It will be much faster than accessing files from Windows and it can also be a little buggy.

Pin Your Code Directory

Another quick tip I have is to create a code directory inside of Ubuntu, and then pin it to the quick access menu found on the left side of the file explorer. This comes in handy when transferring files quickly between Windows and Linux.

  1. Open file explorer and click on the Ubuntu network drive we created
  2. Select the home dir, and then your user directory
  3. Right-click and create a new folder, name it code, or anything else you'd like
  4. Drag that new folder to the left, underneath the star icon that says Quick access

Restarting WSL

If for some reason WSL stops working, you can restart it with these two commands from PowerShell/Command Prompt:

wsl.exe --shutdown
wsl.exe

If you go back to your Linux shell everything should be back to normal.