WSL: Quick Setup

windowswsllinuxubuntuwsl-series


Introduction

WSL or Windows Susbsystem for Linux is a Microsoft Windows feature that let developers run a Linux Environment on Windows. WSL2 includes a real Linux Kernel.

To learn more about it, read here.

Initial Configuration

On Windows $HOME folder create a file .wslconfig

Set-Location $HOME
New-Item -Path ".wslconfig" -ItemType File

Then add the following to .wslconfig

[wsl2]
networkingMode=mirrored

TIP

To learn more about .wslconfig go to official docs

Install WSL

Open PowerShell in admin mode and run

wsl --install -d Ubuntu

After logging in you will need to:

  • Create default user (leave it with default Windows user)
  • Set Password (use Windows PIN for convenience)

If already installed, check you are using a wsl2 version first

wsl --version

# WSL version: 2.6.1.0

By default, the installed Linux Distribution will be Ubuntu. To keep it simple we will work with Ubuntu. Check the distribution has been installed by running

wsl --list

# Windows Subsystem for Linux Distributions:
# Ubuntu (Default)

TIP

You can install other distributions at the same time. When running wsl --list you will see (Default) on the main one

WSL Ubuntu Configuration

Check that systemd is enabled

 cat /etc/wsl.conf

You should check that systemd=true exists

[boot]
systemd=true

Disable interop/appendWindowsPath in /etc/wsl.conf (this includes binaries from Windows on your shell PATH) to avoid Windows Binary clashes. Ideally, the system should run all by itself, but if you prefer you can leave it as true.

[interop]
enabled = true
appendWindowsPath = false

TIP

To learn more about /etc/wsl.conf go the official docs

Initial WSL Ubuntu Configuration

Update apt

sudo apt-get update

Install core utils

sudo apt-get install -y sudo gpg wget vim curl xz-utils wslu ca-certificates systemd systemd-sysv dbus

Install build essentials (gcc, make, perl, etc)

sudo apt install -y build-essential

Log out, wait at least 8 seconds and log in again

exit
wsl -t Ubuntu

# wait at least 8 seconds
wsl -d Ubuntu

TIP

If you wonder why 8 seconds, read The 8 second rule for configuration changes from microsoft

You are now good to go!