Install Windows Subsystem For Linux

Windows 10 and 11 have a Windows Subsystem for Linux (WSL) that allows developers to run a real Linux distribution in Windows. It is real Linux except does not (yet) support graphics, so GUI applications will not work in it. That includes GUI editors such as Visual Studio Code. (If you want to get very technical there are unsupported and complicated workarounds to allow use of graphics in the WSL.) Ubuntu is the default Linux distribution that can be installed by WSL but there are many other Linux distributions that can be installed instead of or in addition to Ubuntu. The best way to install it is as described here.

If you install a Linux using the WSL then there is plenty of documentation and books and tutorials about Linux. A couple of things unique to the WSL that you need to know is that in Windows the WSL filesystem root can be accessed using \wsl$. In Linux, drives can be accessed using /mnt/{drive}. In other words, C: in Windows is /mnt/c in WSL.

Also see FAQ's about Windows Subsystem for Linux | Microsoft Docs.

Installation

See Install WSL. Windows 10 version 2004 (21H2) and higher (Build 19041 and higher) and Windows 11 make it much easier to install WSL. To check which version of Windows you have, execute winver; it will show a window as in the following.

If you have Windows 10 version 21H2 or higher then install WSL using,

wsl --install

If you get a message saying that that is not valid then install WSL using:

wsl --install -d Ubuntu

Since Ubuntu is the default distribution, specifying it will do the same as when it is not specified but there seems to be (or was) a bug in Windows that causes wsl --install to fail without the distribution being specified explicitly.

It is that easy! Much easier than in previous versions of Windows.

After installation you will need to (it will ask you to) create a User Name and Password for the default user. That user will be an administrator. Then it will do some initial setup.

Next you need to (should) apply updates. In Linux the sudo command is used to execute a command as an administrator. The default WSL user can use sudo and must use it to execute commands that require an administrator. One inconvience is that you must enter the password each time you use sudo. If however you use sudo su then you can subsequently use sudo multiple times but enter the password only once. So after issuing sudo su and entering the password, use the command apt update to update the local repository index (it will take a minute to complete) then use the command apt upgrade to apply all the updates (it will take a few minutes to complete). Note that when you use sudo su the prompt will change. You need to exit from sudo su to end it. While sudo su is active when you use the sudo command you do not need to enter the password.

Visual Studio Code and WSL can be used to to develop Linux programs; see Developing in the Windows Subsystem for Linux with Visual Studio Code.