Windows Subsystem For Linux is a great new feature of modern Windows computers to allow users to run Linux operating systems natively on their Windows 10 computer. In addition to Windows 10, administrators can also run Windows Subsystem For Linux on Windows Server 2019 edition. WSL first appeared in the Windows Anniversary Update back in 2016. Since then, Microsoft has taken lots of feedback from users via Twitter, GitHub, and User-voice and has streamlined and enhanced the Windows Subsystem For Linux experience. This is real game changing technology that allows your favorite flavor of Linux whether that be Ubuntu, Red Hat, Kali Linux, Alpine, Pengwin, Debian, or openSUSE, to run right in Windows. In this article, we’ll take a look at getting WSL installed and testing out some of the great features it has to offer.
What Exactly Is Windows Subsystem For Linux?
Windows Subsystem for Linux is a new tool for users of Windows that allows them to run Linux right on Windows. This includes the command-line tools, utilities, and applications that normally only run in a Linux machine, without the overhead of a typical virtual machine. It is a Linux Kernel built from 4.19 and is fully managed by Microsoft, including support for Windows Update. WSL uses a non traditional form of virtualization with a very small footprint. Its more analogous to containers than a traditional VM.
|Slow To Boot||Less than 1 second boot time|
|Memory Intensive||Small memory footprint|
|Needs to be managed manualy||Only runs when needed|
What Can You Do With Windows Subsystem For Linux?
In short, a lot. Here is a quick overview:
- Install the most popular Linux distributions from the Microsoft Store.
Being able to choose from Ubuntu, openSUSE, Kali Linux, Debian, or Alpine WSL is pretty cool.
- Get access to a genuine Linux Shell, right in Windows, and run your favorite commands like
pwd, and others.
- Take advantage of the following Tools, Programming Languages, and Services:
- Tools like vim, emacs, and tmux
- Work With Languages Like Node.js, PHP, Python, C/C++, Rust, GoLang, and more.
- Configure Services Like: Nginx, sshd, MySQL, Hadoop, and MongoDB
- Windows File Access – DrvFs mount options
- Interop – Launch Windows Binaries
/etc/wsl.conf– Configuration Options
- wslpath – Translate paths from one env to the other
$WSLENV– Share env variables between Linux and Windows!
- Background Task Support
Viewing Installed Linux Distros
Once you have one or more installed Linux Distributions installed, you can view them with the
wsl -l command.
How Does It Work?
As we saw above, users can get many different Linux distributions available from the Microsoft Store. These distributions are shipped by Microsoft Partners. Underneath that is the WSL translation layer, implemented as a driver. This is a Windows Driver that implements the Linux Kernel ABI which handles System Calls, Virtual Files, and File Systems. At the base of this architecture is the Windows NT kernel.
Much of this magic happens via the use of System Calls.
Linux binaries make use of system calls to do things like accessing files, requesting memory, and creating processes. In the latest versions of WSL, this is offered via a dedicated Linux kernel with full system call compatibility.
The detailed architecture of WSL is shown here.
Installing Windows Subsystem For Linux
Now that we know a bit about what WSL is and how it works, let’s get our hands dirty and install WSL on our Windows 10 machine. There are a couple of ways you can install WSL. You can enable it as a Windows Feature, or you can use Windows Powershell to turn on WSL. To enable WSL as a windows feature, first type “Turn Windows features on or off” in the lower left hand side of the screen, then click the Best match option.
You will then see a dialog screen come up titled “Windows Features” with a list of various features you can turn on or off in Windows. To turn a feature on, select its check box. To turn a feature off, clear its check box. A filled box means that only part of the feature is turned on. So we will go ahead and click the empty box next to Windows Subsystem for Linux and click the Ok button.
Windows will then look for the needed files and make the changes to your system to enable WSL. Once complete, you will need to restart the machine to complete the installation.
Installing WSL using Powershell
Alternatively, you may install WSL by using Powershell. To do so, you need to open Powershell as an Administrator. If you have the new windows terminal, you can launch Powershell from there. Then you can type the following command and hit Enter.
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Just like the first method, this will also require a reboot to finalize the install.
Choose A Linux Distribution
Now that WSL is installed, you can use any of the following links to add the flavor of Linux that you like.
- Alpine WSL Lightweight Linux Distro based on musl, libc, and Busybox.
- Pengwin Enterprise Pengwin Enterprise is for custom deployments in consultation with Whitewater Foundry’s international team of WSL experts.
- Pengwin Linux distribution optimized specifically for Windows Subsystem for Linux.
- Fedora Remix for WSL Fedora Remix for WSL.
- Debian GNU/Linux Debian for the Windows Subsystem for Linux.
- Kali Linux A simple Kali Linux installation with no penetration testing tools, though they can be added.
- SUSE Linux Enterprise Server 15 SUSE Linux Enterprise Server is built to power physical, virtual and cloud-based mission-critical workloads.
- SUSE Linux Enterprise Server 12 Same as above, version 12.
- OpenSUSE Leap 42 openSUSE is a stable and easy to use multi-purpose Linux distribution.
- OpenSUSE Leap 15 Great for beginners, experienced users, and ultra geeks alike!
- Ubuntu 18.04 LTS Ubuntu 18.04 on Windows allows one to use Ubuntu Terminal and run Ubuntu command line utilities including
aptand many more.
- Ubuntu 16.04 LTS Same as above, version 16.04.
For our install, we’ll choose Ubuntu 18.04 LTS as that seems like a popular flavor of Linux these days.
After you select your Linux distribution, you’ll see it downloading.
After the download completes, you’ll see a notification that Ubuntu has been installed and you can launch it straight away or pin it to the start menu.
On the first launch of our Ubuntu shell, we see some messages
Installing, this may take a few minutes…
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:
If you add a user name that the system does not like, you might see this message.
adduser: Please enter a username matching the regular expression configured
via the NAME_REGEX[_SYSTEM] configuration variable. Use the `–force-badname’
option to relax this check or reconfigure NAME_REGEX.
In our case, it looks like Ubuntu did not like a capital letter in the user name. By using all lowercase letters and adding a password two times for confirmation, we have success!
To run a command as administrator (user “root”), use “sudo
See “man sudo_root” for details.
Behold! The Ubuntu shell running right on Windows!
We can launch the
htop program in Ubuntu to show the genuine Ubuntu shell.
How To Access Windows Files From WSL
While in a WSL command line, you can get access to all of the files on the Windows OS via the
/mnt/d/ directories (depending on the letter assigned to the Windows drive(s)). This is good for easily getting your most commonly used files in Windows, over to the Bash style workflow of WSL. Here we are in WSL listing the contents of the C drive.
Just to confirm we are indeed looking at the Windows file system, if we open Powershell on the Windows PC and list out the contents of the same C drive, we can see the contents match. Cool!
To show this in action, we can create a file using Windows notepad.exe on the Windows machine. Then, we can use WSL with the
nano application to see the contents of that file. Pretty cool! WSL allows you to work with both the Windows and Linux file systems as if they were one, which is really convenient.
Text File Created in Windows.
Now in WSL, watch as we use NANO to open that same file with ease.
How To Access Linux Files From Windows
The same idea holds true in the other direction. Using Windows Explorer, you can gain access to the folder structure of the Linux distribution that is running in WSL. Clicking around the Linux file system using Windows Explorer will have you feeling like you’re living in another dimension! To do this, you can look for the Linux file system in
%USERPROFILE%\AppData\Local\Packages\. There will be many sub-folders within this folder where your Linux file system may be. In our case we have installed the Ubuntu 18.04 LTS distribution, and our folder was found in CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc. Then you will find the
LocalState\rootfs folder which is the root directory of the Linux installation. Here we can see us browsing files in Ubuntu using Windows Explorer.
Working With Python In WSL
Python is a popular programming language for all kinds of tasks, but it really excels in a command line environment where you can automate repetitive tasks and perform basic system administration tasks. Windows subsystem for Linux makes it even easier to work with Python on your Windows PC. You can even find many pre made Python scripts on the internet for these types of tasks, however these scripts always assume you are running Linux. Well guess what? With WSL you really are running Linux! Now there is no need to download and install something like VirtualBox so you can boot up a memory intensive Virtual Machine just to test these simple scripts. Simply launch your Ubuntu shell with one click, and you have what you need.
To be fair, you can run Python on Windows without WSL. For quick tests and one liners however, being able to run Linux Python examples that were meant for Linux machines is a nice productivity gain for power users. Though Python3 is installed, the PIP package manager is not. Fun fact, PIP is a recursive acronym that means either “PIP Installs Python” or “PIP Installs Packages”. This program works much like NPM in Node, or Composer in PHP. Let’s get it installed now.
First we can update the package lists in Ubuntu using
sudo apt udpate.
Now we can run
sudo apt install python3-pip.
Once complete if you check the version with the
pip3 --version command, you’ll see something like pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6) as the output. Fantastic. We now have the ability to use any of the thousands of freely available Python modules like httpie, flask, django, requests, ansible, scrapy, and more to work with.
Learn More About Windows Subsystem For Linux
Are we having fun yet? If you want to get started with Windows Subsystem For Linux and need more information, check out these great resources below.
- Windows Subsystem for Linux Installation Guide for Windows 10 (Microsoft)
- How to Enable the Windows Subsystem for Linux (Wikihow)
- How to install Windows Subsystem for Linux 2 on Windows 10 (Pureinfotech)
- Inspired by Insiders—Windows Subsystem for Linux (Windows Insider)
- The Ultimate Guide To WSL (Adam The Automator)
- How to run Ubuntu using the Windows Subsystem for Linux (Foss Linux)
- How to Get Started With the Windows Subsystem for Linux (Lifehacker)
- Microsoft Put a Real Linux Kernel Inside Windows 10 (OMG Ubuntu)
- Developing on Windows with WSL2 (Subsystem for Linux), VS Code, Docker, and the Terminal (Scott Hanselman)
- How to Use Windows Subsystem for Linux 2 and Windows Terminal (Sitepoint)
Windows Subsystem For Linux Summary
WSL is a fast moving, and big topic. Microsoft is iterating quickly on this technology, as it seems to be a hit with lots of developers and system administrators. In this tutorial we took a look at what WSL is, the architecture of the system, how it works, and what you can accomplish with WSL. In the past if you needed to build a project that relied on an open source package that depended on a Linux installation, you had to either set up a Dual Boot Windows and Linux machine (not fun), install VirtualBox or VMWare Workstation and run a memory intensive Virtual Machine, or configure Docker containers. All of these options carry a lot of grunt work overhead and a steep learning curve if you are unfamiliar with how to set these options up. Now with Windows Subsystem for Linux installed, you can access a full Linux shell in under a second!