How to setup WSL2 with Windows Terminal, ZSH and powerlevel10k

Posted on Fri, Jun 12, 2020 Tooling

I wanted to share with you my recent WSL2 setup on my new workstation which was ridiculously easy to do!

What I wanted

Basically I wanted the same setup that I would run on my MacBook and my Linux machines:

What you can expect

In the following, I will guide you step by step on how I did my setup. A ZSH shell running inside Windows Terminal with powerlevel10k, syntax highlighting, automatic suggestions and Docker support.

Prerequisites

You will need the Windows 2004 update and you have to enable virtualization on your BIOS.

Step 1: Install WSL2

Open PowerShell as Administrator and run the following commands:

# Install WSL
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

# Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

After these two commands, restart your machine and run the next command to set WSL2 as your default version:

# Use WSL2 per default
wsl --set-default-version 2

Step 2: Install a Linux Distribution and Windows Terminal

Step 3: Configure Windows Terminal

Ultimately, you should have an object similar to this:

{
    "guid": "{some-value}",
    "hidden": false,
    "name": "Ubuntu-20.04",
    "source": "Windows.Terminal.Wsl",
    "colorScheme": "One Half Dark",
    "fontFace": "MesloLGS NF",
    "commandline": "wsl.exe ~"
}

Step 4: Install oh-my-zsh

$ sudo apt install zsh
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

You may want to restart Windows Terminal for a new session.

Step 5: Install useful plugins and configure ZSH

$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
$ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

Open ~/.zshrc and modify its content like this:

# Use Powerlevel10k theme
ZSH_THEME="powerlevel10k/powerlevel10k"

# Use plugins
plugins=(docker zsh-autosuggestions zsh-syntax-highlighting)

After setting the theme, the Powerlevel10k wizard should show up, which will guide you through the setup. If it did not show up then try to run p10k configure. More about oh-my-zsh plugins and Powerlevel10k configuration.

Step 6: Docker and VS Code

Docker also supports Windows Home since the 2004 update! Follow their guideline Install Docker Desktop on Windows Home. After the installation Docker should automatically use the WSL2 backend. That was at least the case for me. If it wasn’t for you, then please follow this documentation.

VS Code has of course great support for development inside WSL2 with this extension. The README should be sufficient documentation.

And we’re done 🎉

With this setup you should have a full-blown development setup inside WSL2 and a nice looking Windows Terminal. I am very pleased with this setup and since the last years Microsoft keeps surprising me every time!