If you have developed on both platforms (Windows and Unix-like OS), you’d advocate the fact that Windows CLI has been extremely outdated and lack tons of useful commands and features which are just inherent to Linux. Microsoft’s try on solving this problem was Powershell but it’s still miles off a standard Linux bash. However, I recently discovered this amazing new Windows feature called “Windows Subsystem for Linux” that came up in search when I Googled “How to run Linux bash shell on Windows” at 3 in the morning (so try at your own risk). It’s quite fascinating and appears to be what Windows has been missing for ages. Apparently there’s a Windows Subsystem for Linux 2.0 in its BETA. So let’s dive into WSL and see what’s what!
Windows Subsystem for Linux (WSL)
Windows Subsystem for Linux (which is actually Linux subsystem for Windows) is a Microsoft supported Windows feature that allows you to run Linux on your Windows machine. When I say “run Linux on your Windows” machine, it’s not a typical virtual machine style Linux distro running on top of your Windows needing a separate virtualisation product (such as Oracle VirtualBox) and a separate ISO image of your favourite Linux Distro with manual allotment of CPU and RAM. To be honest, I am not entirely sure the underpinnings of how it works but who cares. For a cold start, it takes no more than 3 seconds to be up and running. The process looks something like this:
1. Go to Control Panel > Programs and Features > Turn Windows features on or off. Select “Windows Subsystem for Linux” and click “OK”. Windows will ask you to reboot your machine.
2. Go to Microsoft Store and search for Linux. You will see most of the popular Linux distros there to download for FREE
3. Install the one of your choice. I went with Ubuntu 18.04 LTS since it has long term support for five years starting 2018
4. Once the distro is installed, it will appear in your Start menu, clicking on which will simply open a Linux bash shell – Wohoo!!
Now this Linux bash shell is not something that pretends to be a Linux-style terminal with git
and scp
commands enabled by default. It’s an actual, tangible Linux bash – from Linux itself. How it works is like this: It create the most minimalist, trimmed-down VM (run as vmmem
in Windows Task Manager) and mounts your Windows file system onto Linux which you can then access by doing cd /mnt/c/
which is the C:/
directory of your Windows machine. You can run all your Linux commands in this mounted directory as you would in any Linux directory. It’s fast and it’s awesome! Running explorer.exe .
in your Linux bash opens up a File Explorer with a Network entry of wsl
, allowing you to view your Linux file system on Windows, making it a two-way street!
Now you must be thinking would it run Python, Docker, VS Code and all that jazz that is native to Linux and is normally taken for granted? The answer is: YES! You can bring up Docker for Windows and pull a Docker image in your Linux bash. When running a container, you can publish a port, localhost of which will be accessible by your Windows browser. So if you do:
docker run --detach --publish 8888:443 --publish 8067:80 --publish 8066:22 --volume /srv/gitlab/config:/etc/gitlab gitlab/gitlab-ee:latest
on your newly installed Linux bash, you will be able to access your Docker container by typing localhost:8888
in your Windows browser. How cool is that?
Run Multiple Linux Distros
Another great thing about WSL is that you can install as many distros as you like and run them simultaneously. However, it should be noted that file system of each distro works in isolation where each distro mounts C:/
drive in its /mnt
directory for you to use. Re-opening a distro, for example ‘Ubuntu’, simply initiates another session of Ubuntu just like another tab in a terminal.
WSL also has small executables that allow you to run different distros of installed Linux via command line. wsl --list
lists all the available Linux distros you have installed and wsl -d {distro-name}
simply kicks off that distro with Admin privileges.
Windows Terminal
Another great tool that caught my attention is Windows Terminal. It has recently been out of its Preview mode and available as an open-source Windows console to be installed from Microsoft Store. It’s a very smart console with all popularly used shells that are just a click away. By default, it includes Powershell, Powershell Core, VS2019 Powershell and Azure Cloud Shell. If you have Linux installed on your Windows, it also shows you its shell.
Windows terminal comes with a configuration file (in JSON format, of-course), which allows you to have whatever profile you wish to choose. You can modify font family, font size, padding, available size of history of bash commands, and much more. However, it should be noted that minimum system requirements for running Windows terminal is Windows 10 version 18326.0 or higher. You can check the version of your windows by running winver
command in Windows command prompt.
To be honest, it has been literally couple of hours I have been using WSL but I really think this is exciting times for Developers to develop on Windows when tools like these are at your disposal!