Fundamentals 14 min read

Master WSL2 on Windows: Step‑by‑Step Installation, Configuration, and Optimization

This guide walks you through what WSL2 is, compares it with WSL1, explains why to use it, and provides detailed step‑by‑step instructions for enabling the required Windows features, installing Ubuntu, customizing the terminal, updating package sources, and even uninstalling the subsystem.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Master WSL2 on Windows: Step‑by‑Step Installation, Configuration, and Optimization

1 What is WSL2

WSL (Windows Subsystem for Linux) lets you run a GNU/Linux environment directly on Windows, including most command‑line tools, utilities, and applications.

WSL1 vs WSL2 comparison :

Both integrate Windows and Linux and have short startup times.

WSL2 provides a full Linux kernel, complete system‑call compatibility, and a hosted VM.

WSL2 uses more resources than WSL1 but offers better performance for many workloads.

Both can run alongside VMware or VirtualBox.

Why use WSL2 : It gives you the Windows GUI you love while providing a native‑like Linux command line, enabling shared file systems, Docker containers, and low‑overhead development.

2 Install WSL2

Prerequisites : Windows 10 version 2004 (or later) or Windows 11, and a machine that supports Hyper‑V virtualization.

Enable the "Virtual Machine Platform" feature (required for WSL2) with administrator PowerShell:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

For older Windows 10 builds (1903/1909) use:

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart

After enabling, restart the computer.

Install the default Linux distribution (Ubuntu) with: wsl --install The command enables the optional WSL components, downloads the latest Linux kernel, sets WSL2 as default, and installs Ubuntu.

If WSL is already installed, list available distributions and install a specific one:

wsl --list --online
wsl --install -d Ubuntu-20.04

Check the installed version: wsl -l -v If needed, set Ubuntu to use WSL2: wsl --set-version Ubuntu-20.04 2 Launch Ubuntu, create a user and password, then you can start using it with wsl from PowerShell.

2.3 Install Ubuntu on a different drive (e.g., D:)

Create a folder such as D:\Linux and download the Ubuntu .appx package:

Invoke-WebRequest -Uri https://wsldownload.azureedge.net/Ubuntu_2004.2020.424.0_x64.appx -OutFile Ubuntu20.04.appx -UseBasicParsing

Rename, extract, and run the installer:

Rename-Item .\Ubuntu20.04.appx Ubuntu.zip
Expand-Archive .\Ubuntu.zip -Verbose
cd .\Ubuntu\
.\ubuntu2004.exe

3 Update Linux package sources

Replace the default /etc/apt/sources.list with a faster mirror (e.g., Aliyun or Tsinghua):

# Example Aliyun mirror entries
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
... (other lines omitted for brevity)

If you encounter certificate verification errors, change https to http, reinstall ca-certificates, then revert the URLs and run sudo apt update && sudo apt upgrade.

4 Install Windows Terminal

Download Windows Terminal from the Microsoft Store (search for "Windows Terminal"). After installation, set Ubuntu as the default profile by editing the generated profiles.json and replacing defaultProfile with Ubuntu's GUID.

4.1 Install oh‑my‑zsh

In Ubuntu, install zsh and git:

sudo apt update
sudo apt install git zsh -y

Change the default shell: chsh -s /bin/zsh Install Powerline fonts:

git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh

Install oh‑my‑zsh (using a Chinese mirror if needed):

wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
chmod +x install.sh
./install.sh

4.2 Configure theme

Edit ~/.zshrc to set the theme to agnoster or robbyrussell, then tweak the theme file ~/.oh-my-zsh/themes/agnoster.zsh-theme to customize colors.

4.3 Add plugins

Install autosuggestions and syntax‑highlighting plugins:

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

Add them to the plugins array in ~/.zshrc and reload:

source ~/.zshrc

5 Uninstall WSL

List installed distributions: wsl --list --all Unregister a distribution (replace <System_name> with the actual name): wsl --unregister <System_name> Delete the remaining files from the installation path if necessary.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Development EnvironmentterminalPowerShellWindows Subsystem for LinuxWSL2Linux on Windows
Ops Development Stories
Written by

Ops Development Stories

Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.