WSL2 — Install and Configure on Windows10/11

Windows Subsystem for Linux (WSL) lets you run a GNU/Linux environment within your windows system without using a virtual machine. You can run most of your favorite Linux tools/utilities like grep, vim, etc. and also run shell scripts directly from your windows terminal.

Pre-Requisites

You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.

Install

You can now install WSL on windows using a single command from PowerShell (run as administrator).

wsl --install

Above command will install all optional components along with a default distribution (Ubuntu). When you launch your distribution for the first time, it’s going to decompress all the files to save on your machine. This will take some time. Subsequent launches should be quick. In case you want to install a different distribution, you can tweak the command like this

  • To change the distribution installed : wsl --install -d <Distribution Name>. Replace with the name of the distribution you would like to install.

  • To see a list of available Linux distributions available for download through the online store : wsl –list –online or wsl -l -o

  • To install additional Linux distributions after the initial install, you may also use the command: wsl –install -d

For more details on WSL installation, you can refer to Microsoft documentation

If you want to manually install WSL on older versions of windows, you can refer to this doc

Configure

After installing your preferred distro in WSL, you would want to configure it with tools to suit your DevOps workflow. I work a lot with Azure, Terraform and Azure DevOps. I like to set up my WSL instance with all the tools/utilities that can help with my routine tasks.

Installing and configuring each tool can take a lot of time. To make things easy, I have written an ansible playbook that configures my WSL instance with all the configuration that I need. This helps me get started with my work on any new instance in minutes. I tweak this playbook now and then to suit my current workflow.

The Ansible playbook is hosted on my GitHub

The first thing that you should do after installing your WSL distro is to update all the packages. You can do that by running the following command

sudo apt update -y && sudo apt upgrade -y

After updating the packages, we need to now install ansible to run our playbook. Use the below command to install ansible

sudo apt install ansible -y

Now clone the GitHub repository using the below command

git clone https://github.com/dKm10/wsl-ubuntu-setup.git

Change your directory to the devsetup folder within this repo and run the ansible playbook using the below command. Enter the sudo password when prompted

ansible-playbook -K playbook.yml

Even though you can run this playbook on an already running instance of WSL Ubuntu, for best results I recommend running this as soon as you have launched your distro for the first time.