My Windows text editor was choking while prettifying a complicated XML file, and I wanted to be able to use XMLint without having to set up a Linux VM.
One of the cooler features of Windows 10 is the Windows Subsystem for Linux, or WSL for short.
WSL basically lets you have a full, real Linux installation running on Windows, and you can access it from a command prompt. It’s has its own filesystem, but you can interact with your Windows filesystem and vice versa.
So how it works is this. You need to enable the Windows Subsystem for Linux on your computer, and then you can pick the flavor(s) of Linux to install, many of which are available for free from the Windows store.
Once you’ve installed the WSL and a Linux distro for WSL, all you need to do is fire it up from the command line. Neat.
In Windows, go to the Control Panel, and select Programs. In the Programs and Features section, click on “Turn on Windows features on or off”.
In the resulting dialog, make sure Windows Subsystem for Linux is ticked, and click OK. You’ll probably get another dialog telling you to reboot, so save any open files and reboot.
That’s all it takes to get setup, so now you need to add one or more Linux distributions.
Install a Linux Distribution
Open up the Windows Store app on your computer and search for “wsl” (without the quotes). You should get a list of available distributions for WSL. The big ones are free, but some people have put up other distributions for a fee.
Just pick a distro and click on the “Get” button that appears on the page. For this example, I’m going to assume that you picked “Ubuntu”, which is probably the most popular Linux Distribution.
Note that I did not pick an Ubuntu LTS version, but if you choose one of those, the launch command may be different. The launch command is usually in the Windows Store description for the distro.
You will be prompted for a location to install the Linux distro. The distro needs to be installed on a system drive, so C:\ is usually a good destination.
It’s that simple.
Launching the Linux Shell
Once it’s done, fire up your favorite terminal app. I use CMDer, but the built in command prompt is fine.
Enter this command:
The command prompt will change to look like
From there, you’re able to the command line as though you are SSH’ed into a Linux box. You can install packages and services etc. just as though it was running in a virtual machine. If you are planning on running services, make sure that you use port numbers that don’t conflict with any services you are running on Windows.
To access Windows files from WSL
All of your Windows drives are accessible from the /mnt path. For example, your C drive is at /mnt/c
To access your Linux Files from Windows
If you’re a version of Windows older than Windows 10 Version 1903*, you will have to set up Samba or something like SFTP to access your Linux files. It’s inconvenient, but not for long.
Microsoft has received a lot of feedback and fixed this in Windows 10 Version 1903 by allowing you to use Windows Explorer to access your files natively from the WSL command prompt. To access your Linux files from 1903, you open up an Explorer instance from your WSL command prompt using:
There is a gotcha with respect to accessing Linux files from Windows, irrespective of your chosen method. Your Linux instance must be running for Windows to be able to see the files.
* At the time of posting, Windows 10 Version 1903 is due to arrive by the end of May 2019.
To upgrade your Distro
In many cases, you can update your Linux distro from the WSL command line. For the Ubuntu distro, you can use this command:
If you’re using another distro, the command may differ.
Other articles by this author:
- Power Up Your Productivity on Windows with AutoHotkey Macros
- Get To Know Extrata, Episode 1: The Command Line Interface
- Quick Hit: LibreOffice 6.0 Coming Soon
- Make Your Life Easier With This Software On Your Windows Cognos Server
- Generating a Non-Expiring API Token for Facebook Insights