You can now run Linux apps on Windows thanks to a feature called Windows Subsystem for Linux ("WSL" for short). But what is it, exactly? Is it an emulation layer like Wine? Is it a VM like VirtualBox? Is it dual-booting like Boot Camp? It's none of the above—it's something pretty unique and hard to explain.
Next: Let me try to explain it anyway!
To get Linux working on Windows, you first need to install Linux. Not from an ISO... but from the Microsoft Store (think: Windows's version of the Mac App Store). A full guide to installing WSL is available from Microsoft.
Linux distributions are available as apps. To be specific, they're command-line apps, just like
Next: To understand WSL, let's first look at how the Windows command line works.
Windows has support command line interface (CLI) apps, just like Linux. In fact, many built-in system utilities are CLI apps.
💡 Try this: press
R, then run
ping 220.127.116.11. It will open a new window.
👇 Next: Let's see what makes this window work.
CLI apps are ran inside the Windows console host. The console host, or conhost.exe, is a GUI app that draws a terminal inteface in a graphical window.
💡Try this: open the task manager (
Esc). Now run
ping -t 18.104.22.168. You'll see a new application in the task manager called TCP/IP Ping Command. Under this group are 2 processes:
- ping.exe—the command you just ran; and
- conhost.exe—also known as Console Window Host, the GUI that shows ping's output.
In Linux terms: Think of conhost.exe as a terminal emulator, like XTerm might be for Linux. It's a graphical UI that shows terminal output. ping.exe runs on conhost.exe in the same way /usr/bin/ping runs inside Xterm.
👇 Next: Let's see how the Windows Command Prompt works.
All CLI apps open in conhost.exe. This includes the Windows Command Prompt, or cmd.exe—which is a CLI app, just like ping.exe!
💡 Try this: Go to
R and run
cmd.exe. You'll see this open in the same Windows console host window that
In Linux terms: Think of cmd.exe like the Bash shell. A terminal window in Linux will run Bash, and will close the window when Bash exits. cmd.exe (the shell) and conhost.exe (the terminal GUI) works the same way.
Next: This may be the case for the Command Prompt, but why does Powershell's window look different?
If you open Powershell, you'll notice that the window is blue. It's not a different app, it's still the same conhost.exe with different settings! You'll notice it has the same menus as cmd.exe.
Powershell.exe is a CLI app, too—just like
cmd.exe. Conhost simply lets you choose different settings per app. It simply comes with different color settings for Powershell by default.
In Linux terms: Most terminal emulators on Linux would support different profiles, and you may be assigning different profiles per command. Windows's conhost.exe has a different profile for Powershell that has its Screen Background set to blue.
Next: Is WSL just like cmd.exe and Powershell then?
Yes! You can think of WSL as another CLI application just like cmd.exe and powershell.exe. Just like other CLI apps, you can run
wsl.exe. This is the WSL Launcher, which boots up the WSL platform and drops you into the bash (your user's shell by default).
💡 Try this: Try running
R. This should get you a Linux bash prompt running inside a conhost.exe window. Seems very similar to Cmd and Powershell, doesn't it?
Next: Let's try mixing all these together.
Windows's cmd.exe and powershell.exe can run command line applications. You can use it to run
chkdsk.exe, or—wouldn't you know it—even
💡 Try this: Try running
bash.exe from within a Command Prompt (cmd.exe). In fact, try running
cmd.exe, or any combination above! Typing
exit will bring you one level out.
Next: Why do the backslashes (
\) in Windows appear as forward slashes (
/) in WSL?
WSL has its own filesystem! If you do
ls / inside WSL, you'll find
/bin and the other usual suspects in a Linux filesystem. This is a full POSIX-compliant filesystem managed by WSL, away from the limitations of your Windows's NTFS.
💡 Try this: Go to your Linux's home directory with
cd. Create two files with the same filename, but different case:
touch xyz.txt XYZ.TXT. These two files can't co-exist in Windows's case-insensitive filesystem, can it? They will live happily inside WSL just fine.
In Linux terms: Think of WSL as a separate Linux system—a bit like a VirtualBox VM. It has its own filesystem, processes,
/dev devices. Running
wsl.exe will tunnel you into this Linux subsystem.
Next: So is it a virtual machine?
Not only does WSL have its own filesystem, it's a full Linux system that runs as an app in Windows! It may be easy to think it's like VirtualBox, but it's not a VM.
Why is it not a VM? There's no CPU or hardware emulation involved like in a VM. A whole Linux system runs like any other app in Windows.
💡 Try this: Run
htop inside WSL (you may need to install it first), and view it as a tree (
shift-T). It has a whole process tree, even with an
/init process! You'll see your machine's full CPU and memory capacity—it's not pre-allocated, unlike a VM. It shares these hardware resources just as any other Windows app would.
In Linux terms: On a typical system, Linux's entry point would be in /boot/vmlinuz-linux, which is fired by a bootloader like GRUB. Think of WSL as a version of this packaged as a wsl.exe file. The whole Linux subsystem will be running as a process inside Windows.
Note about WSL2: There are two versions of WSL. The new experimental version, WSL2, actually works as a Virtual Machine.
Next: If WSL is a separate subsystem from your Windows environment, how do they share files?
Your Windows files are visible inside WSL under
💡 Try these: Here are some experiments you can try inside WSL:
Case insensitive files: In WSL, try
cd /mnt/c/WINDOWS. They'll both work! The Windows filesystem you're accessing in
Check mount points: Run
findmnt. You'll see
/mnt/cis mounted as drvfs, just as how you would mount a drive in Linux.
Two home directories: Look at
/mnt/c/Users. You'll see you have 2 home directories: your WSL/Linux one in
/home, and your Windows one in
Permissions won't work: Try to make a file in
chmodto change its permissions. It won't work—the filesystem these files live on is NTFS, which doesn't support UNIX-style permissions.
Next: We can see Windows files in WSL. Can we see WSL files in Windows?
WSL exposes your files as a network resource in
\\wsl$. (The actual files live somewhere in
C:\Windows, though it's not a good idea to use them directly.)
💡 Try this: Open Windows Explorer. In the location bar, type in
\\wsl$\Ubuntu. This should get you access to the WSL filesystem as a network folder.
In Linux terms:
\\wsl$\Ubuntu is called a UNC path, which is Windows's way of accessing network resources. Think of it like
You can run Windows
*.exe programs inside WSL. It will simply open them in Windows, just as you would have ran those programs from Windows itself.
💡 Try this: In WSL, type
notepad.exe. In fact, you can even try running
cmd.exe—this should get you a Windows command prompt! To see how this works, try
which notepad.exe, which shows that it's simply running
user@desktop ~$ notepad.exe
In Linux terms: Linux can run ELF binaries (ie, Linux's native executable format). Once it finds a PE32+ binary (ie, Windows's format), it'll simply tell Windows to open it outside of WSL. Also, Windows's
%PATH% carries over into Bash's
$PATH, making the system
.exe files available anywhere in WSL.
Linux apps can be ran from Windows using
wsl.exe, the WSL launcher. This starts up the WSL subsystem (if it hasn't been yet) and runs a command from within it.
Try this: Open a command prompt (
R to run
cmd.exe), then type:
wsl ls /
Microsoft Windows [Version 10.0.18985.1] (c) 2019 Microsoft Corporation. All rights reserved. C:\>wsl ls / bin/ dev/ home/ lib/ lost+found/ mnt/ proc/ run/ boot/ etc/ init* lib64/ media/ opt/ root/ sbin/ ...
Next: Can we replace conhost?
You don't need to use conhost.exe to run CLI apps. You can run them in third party terminal emulators. There's wsltty (based on Cygwin's mintty), Terminus (an Electron-basde terminal), Conemu (supports tabs and panes), and a few more.
Any of these apps can run any CLI application. They often usually come with built-in shortcuts for cmd, Powershell, WSL, and possibly a few others.
In Linux terms: Just like XTerm has many alternatives, conhost has its own alternatives as well.
Next: Let's recap what we know so far.
Ubuntu is a command-line app. It's installed from the Microsoft Store.
wsl.exethat launches an installed Linux distribution (Ubuntu in this case). This is a command-line program that brings you to a Bash prompt. There's also
bash.exe, which does the same thing (it's like an alias for "wsl.exe bash").
CLI apps: are ran inside
conhost.exe, the built-in Windows terminal. There are alternatives to this that developers might like better.
wsl.exeruns the WSL subsystem and drops you into a Bash prompt. It's just a CLI app.