The WSL (Windows Subsystem for Linux) project, also known as bash on windows, aims to reduce some of the friction you might feel when developing on a Windows system, and make your local work flow more closely resemble your remote environment. It does this by giving you access to a large subset of features from the Linux distribution of your choice. That means you can run loads of useful *nix tools on windows (bash, lamp-server, python an much more), natively. Currently only Ubuntu, Kali and few other flavors are officially supported, but this is an open source project and there is potential for any or all of the more popular distributions to make their way to the platform in the near future.
Why Bash on Windows?
There have always been options for Bash on Windows, namely GitBash or a virtual machine running a linux distribution. Both are great options but have a few limitations
Gitbash/Cygwin has always been a great option. It’s a fantastic piece of software that gives you access to a large number of bash commands, as well some other handy things like the ability run shell scripts. The main downside though, is that while it feels Unix like, at the end of the day, it’s just a series of wrappers over native functions. That means you don’t get the advantage of a package installer, and even if you did Windows wouldn’t know what to do with the packages natively.
The more robust option has always been to have Linux running inside a virtual machine. This gives you all of the functionality, but it has some downsides too. The first big downside is that the virtual machine, by default, has no access to the local filesystem. There are options to create shared folders between systems, but to me that process has always felt a little clunky, and requires configuration within the Virtual Machine, which isn’t always that intuitive. The other big downside is that Virtual Machines require a lot of resources, since you are essentially running an OS on top of an emulated machine, on top your host OS. This isn’t necessarily a big deal if you have a fairly high-powered machine, but when you running it alongside the other tools in a common workflow(PhotoShop, Illustrator, An IDE, etc;) it can really impact performance on a low to mid-range machine.
Native Bash on Windows via WSL offers us a nice middle ground, as we get access to many familiar commands, as well as package installers, and support for a large number of packages (not everything is supported, but more on that in a second), without the overhead of a VM. Bash also has access to the host filesystem, without any additional configuration.
Limitations of Bash on Windows
A quick word of warning:
At the time of writing, WSL is not a perfect solution. There are a few things that may be a deal breaker for some users. The most common are:
I/O latency – Some file operations are a little slow using the bash tools. In my experience, it hasn’t been a huge problem, although writing large files does occasionally hang my machine.
Lack of package support – Most of the packages I use on a regular basis have worked just fine. No issues with apache-server, php, mysql, yarn, python3 and several others. There are some packages, however that have many reported issues. There is community maintained compatibility list that is a good starting point, however, it doesn’t appear to be completely up to date, as several packages are poorly rated, which seem to be working fine since the official release
What can you do with WSL?
- Use Linux command line utilities to work on Windows files – though as of now the opposite is not true.
- Create a local development LAMP server without the need for a Virtual Machine, or a program like WAMP, AMPPS, etc;
- Use Bash scripts to automate repetitive tasks – no need for GitBash or Cygwin
- open SSH without PuTTY or Git BASH
- Native Git support
Getting started with WSL is a snap. All we need to do is:
- Enable it
- Install a distribution
- A tiny bit of setup to give us access to the files we want to work with
That’s it. The whole setup process shouldn’t take more than 30 minutes!
Enable WSL in Windows Features
- In the search bar, start typing ” Turn Windows Features On or Off
- In the box that appears, check the box that says “Windows Subsystem for Linux” fig 1
- Click Ok
- When prompted, restart your machine
Installing a Distribution
- Go to https://aka.ms/wslstore
- If prompted, select Open Microsoft Store
- Select Ubuntu from the Microsoft store page. You may use any of this distributions, however, if you are new to Linux it is recommended to follow along with Ubuntu, as some commands and programs vary between distributions.
- Select “Get”
- Run the Ubuntu installer. This will open a bash session
- When prompted enter a user name. This does not need to match your Windows usernameFig 2
- When prompted, enter a new password for Linux. This will be your root password for elevating from the Bash command prompt
- When the install is finished open Windows Powershell
To open an interactive Bash prompt you can type
or if you just need to run a single command you can do so by typing
In Part two we will look at some additional setup that will help start using this to streamline our work flow.