Windows Subsystem for Linux (WSL)
Windows and Linux are the most widely used operating systems in the world. Yet the two could not be more different. Windows is a commercial product from Microsoft, one of the largest software companies in the world. In contrast, Linux, as “Free and Open Source Software” (FOSS), is a joint effort by thousands of volunteers.
Windows is mainly used in private and business environments. Linux runs on the servers and computers of professionals and private individuals. Many developers use Linux. In addition, the open operating system is the basis for the Android mobile operating system.
The Windows Subsystem for Linux (WSL) gives Windows users access to thousands of software packages and open source tools which are available free of charge. Previously, this required setting up a virtual machine or rebooting the computer in a dedicated dual-boot Linux environment. However, with WSL, all it takes is a few clicks.
What is the Windows Subsystem for Linux?
The Windows Subsystem for Linux is a compatibility layer that allows native Linux programs to be executed directly from the Windows command line. Specifically, the WSL allows 64-bit Linux binaries to be executed in the standard Executable and Linkable Format (ELF).
The Windows Subsystem for Linux is available starting with Windows 10. But Microsoft’s interest in making it easier for Windows users to work with Linux tools from their familiar desktop environment goes back further. For example, WSL emerged from the “Microsoft Windows Services for UNIX” (SFU/Interix) project, which in turn was a further development of the “POSIX subsystem” already integrated in Windows NT. With the Windows Subsystem for Linux 2 (WSL2) this development continues.
Before the release of WSL, users had to try to combine the best aspects of the Windows and Linux universes. In principle, there were two ways to make Linux programs run under Windows:
- Use of a virtual machine. A complete Linux installation is used as a virtual computer under Windows. The approach is user-friendly and allows the full use of any Linux applications, but requires some hardware resources. Furthermore, there is limited interchangeability between running programs on the two operating systems.
- Use of the Linux runtime environment Cygwin. This is installed under Windows and allows the use of many popular Linux programs. The exchange between Windows and Linux programs is possible with Cygwin, but to a limited extent.
Furthermore, users could set up Linux parallel to the existing Windows installation. However, this setup, known as dual boot, requires restarting the computer to switch to the respective operating system. An exchange between running programs from Windows and Linux is therefore not possible with this option.
The Windows Subsystem for Linux does not need a virtual machine and is therefore performant. However, there is no complete Linux Kernel on board, so not all applications are supported. In particular, the WSL alone does not allow the execution of Linux programs with a graphical user interface (GUI). Approaches exist for this as well, but they require additional steps for installation and configuration.
What are the requirements for using WSL?
You don’t need any special system requirements to use the Windows Subsystem for Linux. Your computer only needs to have an x64 or ARM processor, which is the case with almost all modern systems. Furthermore, you need a 64-bit Windows 10 version 1709 or later. If you are not sure which Windows edition and version you are using, you can check it with the following steps:
- Press the Windows logo key + [R], type “winver” in the text box that appears, and press [Enter].
- Alternatively, click Start > Settings > System > About > Windows Specification and read the values there.
How do you activate/install Windows Subsystem for Linux?
The process of activating the Windows Subsystem for Linux on your system is simple. We’ll show the process here for home users. Proceed as follows:
- Click Start > Control Panel > Programs > Programs and Features > Enable or Disable Windows Features.
- Place a check mark next to “Windows Subsystem for Linux”.
- Restart your computer.
- Open the Microsoft Store and search for “Linux”. You will be presented with a selection of available Linux distributions.
- Click the Linux distribution you want, and then click Install. If you are not sure which distribution is right for you, we recommend installing “Ubuntu Linux”.
- After the installation is complete, click on “Start”.
- In the appearing window, packages are downloaded and unpacked at the first start. This may take a few minutes. Finally, you will be prompted to set a username and password for the new Linux installation.
You can run multiple Linux distributions in parallel with WSL. In this case, create a separate user account for each distribution.
As an alternative to the first two steps, you can also use the following PowerShell command to enable Windows Subsystem for Linux. Please note that you have to execute the command as administrator. After execution, restart your computer and follow our instructions from step 4.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
What are the first steps with the Windows Subsystem for Linux?
Which are the first steps after activating the Windows Subsystem for Linux and installing a Linux distribution? This depends on the purpose of the WSL. A web developer usually needs a different application profile than an app developer. We’ll summarize a few frequently needed first steps here.
Show and control installed WSL
The Windows wsl.exe tool is used on the command line to control the installed Linux distributions. Open a command line and enter the following command to display the available options of the wsl command:
wsl --help
Use the official Windows subsystem for Linux command reference from Microsoft to dig deeper.
Using the Windows Subsystem for Linux to show the Linux distribution
You can use the Windows Subsystem for Linux to install and use multiple Linux distributions. Run the following command on the command line to get an overview of the installed distributions:
wsl --list --verbose
Using the Windows Subsystem for Linux to start the default Linux distribution
To start the Linux distribution as default, it is enough to execute the wsl command without any other parameters:
wsl
Afterwards, you’ll be logged in as a Linux user and can directly access the known Linux commands.
Using WSL to update the Linux distribution
As soon as you have logged into your Linux distribution for the first time, update the installed software packages, using the following command:
sudo apt update && sudo apt upgrade
Since this is an operation that has system-wide influence at the Linux level, the command begins with “sudo”. You will then have to enter the password set during the installation of the Linux distribution.
Using Windows Subsystem for Linux to install Git
Git is the most widely used tool for versioning code projects. To install Git within the Linux distribution, use the following command:
sudo apt install git
Using Windows Subsystem for Linux to use Linux tools from Windows
You have already seen how you can log into the Linux distribution using the wsl tool and then use Linux commands. Besides that, there is an alternative method. You can run Linux commands directly from the Windows shell. This can be useful, for example, to use Linux commands in PowerShell scripts. Simply add the Linux command to the call of the wsl tool:
# use Linux-Command `ls` to output contents of the current directory
wsl ls -la
Using Windows Subsystem for Linux to use Windows tools from the Linux command prompt
As you have seen, you can use the WSL Linux command to run scripts directly from the Windows command line or from PowerShell. This also works the other way around: you can use Windows command line tools at the Linux command prompt or in Linux scripts. The command line tools can be combined like regular Linux commands.
Here we’ll use the Windows tool ipconfig.exe to display network information in combination with the Linux tools grep to filter the IPv4 results and cut to remove the column fields:
ipconfig.exe | grep IPv4 | cut -d: -f2
Where to use the Windows Subsystem for Linux
Primarily, the WSL serves to use Linux commands on the command line and in scripts. It can also be used to link Windows and Linux tools. This makes the WSL highly relevant for developers. For web development and open source programming in particular, it’ll be is easier with WSL enabled. With Windows Subsystem for Linux enabled, you can, for example:
- Install one or more Linux distributions from the Microsoft Store.
- Use popular command line tools such as “grep”, “sed” and “awk”.
- Run other ELF-64 binaries.
- Run scripts for the Bash shell and other shell environments.
- Use terminal-based applications such as “vim”, “emacs”, and “tmux”.
- Use programming languages and associated tools, e.g., NodeJS, Javascript, Python, Ruby, C/C++, C# & F#, Rust, Go, etc.
- Run Linux services on your machine, e.g., SSHD, MySQL, Apache, lighttpd, MongoDB, PostgreSQL etc.
- Install additional software using the package manager of your Linux distribution.
- Invoke Windows applications using a Unix-like command line.
- Run Linux applications on Windows.
- Unlimited traffic
- Fast SSD NVMe storage
- Free Plesk Web Host Edition