Post

Windows Subsystem for Linux (WSL) Tips

WSL lets you install a Linux distribution (such as Ubuntu) and use apps and Bash command-line tools directly on Windows. Linux runs in a container with a real Linux kernel that allocates only the resources needed.

Easy install

You can install your first container directly from the Microsoft Store.

Setup WSL

Search for “Turn Windows features on or off” in the Windows search bar and ensure that “Windows Subsystem for Linux” is turned on before restarting your machine.

Setup your first container

  • Open the Microsoft Store
  • Search for “Ubuntu” and install the “App” from Canonical (usually the first result).
  • To launch, type “ubuntu” in Windows Terminal, or click on the Ubuntu icon in the Start Menu.

Setup a second WSL container

Getting a second container, or a specific version of a distribution, takes a few more steps.

I recently setup another Ubuntu container for a new project. Below are the steps I used.

Select the image

Download your desired image either with your browser or use the following command in Windows Terminal. I pulled an image from Ubuntu. If you use your browser, move the file to the appropriate directory. https://cloud-images.ubuntu.com/releases/

1
curl https://cloud-images.ubuntu.com/releases/noble/release/ubuntu-24.04-server-cloudimg-amd64.tar.gz --output ubuntu-24.04-wsl-root-tar.xz

Import the image into WSL

Run this command in Windows Terminal to import the image. Substitute UbuntuDev2 for whatever name you wish.

1
wsl --import UbuntuDev2 "C:\Users\Kevin\UbuntuDev2" .\ubuntu-24.04-wsl-root-tar.xz

Start the container

1
wsl -d UbuntuDev2

Setup your user account

By default, you will start as root. Don’t be root forever. Create a user account with the following.

1
2
useradd -m -G sudo -s /bin/bash kevin
passwd kevin

Edit the WSL config

WSL has many configuration options. Advanced settings configuration in WSL | Microsoft Learn

Use vi or a similar editor to edit the file.

1
vi /etc/wsl.conf

I typically use the following options in my container config file.

1
2
3
4
5
6
[boot]
systemd=true
[network]
hostname=Dev2
[user]
default=kevin

Shutdown the image

Once you have made your initial changes, stop the container.

1
wsl --shutdown UbuntuDev2

Shutdown all the running images

Side tip: if you want to shut down all the containers, use the following command.

1
wsl --shutdown 

Verify container states

1
2
3
4
5
6
PS C:\Users\Kevin> wsl --list --all -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  UbuntuDev1             Stopped         2
  docker-desktop-data    Stopped         2
  docker-desktop         Stopped         2

Restart the container and login

1
wsl -d UbuntuDev2

Updates

Don’t forget to run your updates.

1
2
3
sudo apt update

sudo apt upgrade

Check your release info with this command:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
kevin@Dev2:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

Have fun!

Sources / Linkage

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.

© Kevin Schwickrath. Some rights reserved.

Using the Chirpy theme for Jekyll.