Install Linux on Windows with WSL

  • dani


5 min read
Photo by Gabriel Heinzer / Unsplash

When I was temporarily without any Mac, but still had my Windows gaming PC, I wanted to continue coding on the latter. But Windows can be very clumsy for developers. To install e.g. node.js or PHP, you always have to go to a website and download an executable. Then you need to somehow get all in your PATH variable manually. Whereas on Linux or Mac you just fire a command on the Terminal to install the stuff you need and it is there, ready to run. Ultimately, when I needed an Apache webserver the hassle with Windows drove me deep into the thought of installing Linux on my PC.

The main question when installing Linux on a Windows PC is: Do you use a virtual machine, where one is the host of the other, or do you use dual boot? At least, those were the two go-to options I was aware of (stupid me). I tried an Ubuntu VM, which was very slow and its graphics did not work well. So I almost installed the dual boot – until I heard of Windows Subsystem for Linux (WSL).

WSL allows you to install a GNU/Linux system into your existing Windows system – without any virtualization or dual boot setup. It integrates the respective kernel into the Windows system and you run all your Linux applications and (most importantly) all command-line tools directly in Windows. You can also run Linux applications with graphical interfaces using window forwarding. Sounds magical, right? It is a huge quality of life feature for developers. And lets me ask the question: How good is Windows if you need to integrate Linux to make it better? 😉

Installation of Linux with WSL

The WSL documentation for the installation is quite good. And the installation is very easy. All you need is Windows 10 version 2004 and higher or Windows 11. Then run a PowerShell or Windows Command Prompt as administrator and run the command

wsl --install

The command installs the default Linux distribution that is Ubuntu. You can install any custom distribution by importing a TAR file. There are a bunch of distributions you can install from the online store as listed by the command wsl -l -o :

C:\Users\Daniel>wsl -l -o
The following is a list of valid distributions that can be installed.
Install using 'wsl --install -d <Distro>'.

Ubuntu          Ubuntu
Debian          Debian GNU/Linux
kali-linux      Kali Linux Rolling
openSUSE-42     openSUSE Leap 42
SLES-12         SUSE Linux Enterprise Server v12
Ubuntu-16.04    Ubuntu 16.04 LTS
Ubuntu-18.04    Ubuntu 18.04 LTS
Ubuntu-20.04    Ubuntu 20.04 LTS

You can install the respective distro with

wsl --install -d <Distro>

You can even install multiple Linux versions on the same Windows computer. For more details, see the Microsoft documentations.

Use Windows Terminal to access Linux

I never heard that before, but there is indeed a Windows Terminal, a Terminal application for Windows just like you know it from your beloved Linux or Mac system. Basically, the Terminal is an alternative to the Command Prompt (CMD) and the PowerShell. You will use the Terminal to access and control your Linux distribution.

You can install the Terminal from the Microsoft Store using the link or manually, or you build it from the GitHub repository. For more installation options see the Microsoft documentation.

After installing and starting the Terminal, you can click the down-arrow in the menu bar to access your Linux instance (in my case Ubuntu).

Open a new tab on the Windows Terminal by clicking the downarrow
Open a new tab on the Windows Terminal by clicking the downarrow

You can also navigate to the settings and set the default profile to your Linux instance (still Ubuntu for me). That way, every time you start the Terminal it opens a new tab for your Linux instance and if the instance is not running already, start it up.

In the settings, set the default profile to your Linux instance
In the settings, set the default profile to your Linux instance

From the Terminal, you can now run your Linux commands. First thing you should do is update the package manager itself and all applications managed by it. For an Ubuntu instance use

sudo apt update && sudo apt upgrade

Starting up the Linux system

The Linux system should start as soon as you launch your Windows Terminal with the respective profile. For me, it takes some seconds after I start the Terminal and then the Linux system is ready quite fast. After startup, the system shows a message with some status information.

WSL startup on the Windows Terminal
WSL startup on the Windows Terminal

Access the Linux file system

You can access all files of the Linux instance using the Windows Explorer. Inside the Terminal run the command

explorer.exe .

The period . after explorer.exe is very important as it tells the Explorer to open your current directory, i.e. your Linux home directory. If you skip the period, it will open your Windows home directory, not your Linux home directory.

Starting the Windows Explorer to show your Linux home directory
Starting the Windows Explorer to show your Linux home directory

If you click on the wsl$ part in the directory bar in your Windows Explorer, then right-click on the Ubuntu folder and choose Map network drive... (this opens a dialogue where you have to choose a letter for the drive) you can map the directory to a drive (e.g. Z: ) so it is easily accessible from your Windows Explorer.

Map the WSL directory to a network drive
Map the WSL directory to a network drive

In other articles, I explain how to ideally setup local development environments using the WSL Linux instance and Windows together.

If you want to setup PHP, Apache web server, MySQL database and run WordPress on top of that check out my other article.

Install PHP, Apache and MySQL with WSL Ubuntu
Install a local web development environment with PHP, Apache webserver and MySQL database ready for WordPress on Windows using WSL Ubuntu.