In this post we are going to explore what WSL is, what it can do for you as a developer, and how to get it running. To start, I will take a quote directly from Microsoft here:
Developers can access the power of both Windows and Linux at the same time on a Windows machine. The Windows Subsystem for Linux (WSL) lets developers install a Linux distribution (such as Ubuntu, OpenSUSE, Kali, Debian, Arch Linux, etc) and use Linux applications, utilities, and Bash command-line tools directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.
What this means for you is that you can easily run as many different Linux distros as you wish on your Windows machine, without the need for virtual machines or rebooting to each distro as needed. Any Linux distribution that you install will also have full access to the filesystem of your Windows host, and allow you to run Linux based commands and applications at the same time. Best of both worlds in my opinion!
Getting things set up is actually exceptionally simple too. Microsoft has done a lot of work on WSL since the early days, and now you just need to open up a PowerShell window and type in wsl --install
to just go with the default Ubuntu choice. If you want to use something else instead as your default distro, you can use wsl --list --online
to get a list of all available options and then wsl --install -d <DISTRO>
. For example, to install Kali instead you can use the command wsl --install -d kali-linux
. As of the time of writing, available options are:
Ubuntu
Debian
kali-linux
Ubuntu-18.04
Ubuntu-20.04
Ubuntu-22.04
OracleLinux_8_5
OracleLinux_7_9
SUSE-Linux-Enterprise-Server-15-SP4
openSUSE-Leap-15.4
openSUSE-Tumbleweed
Once everything finishes installing, you may need to reboot your computer. But you will now have your chosen distro installed alongside Windows itself, and you can load a terminal window into the OS by the start menu or simply typing wsl
into a PowerShell or CMD prompt. If you want to configure your installation (for example, allowing it to take more memory) you can just create a file in your user directory called .wslconfig
and add the non default options to the file. For example, I want to allow WSL to take a lot more memory, and I would also like to move the swapfile to another drive.
[wsl2]
memory=24G
swapfile=H:\\wsl-swap.vhdx
For a full list of options available, please see https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-setting-for-wslconfig to learn more about the config file.