Microsoft has come a long way since 2001, when then CEO, Steve Ballmer infamously called Linux a ‘cancer’. The more pragmatic Microsoft of this era now accepts the commercial reality that more people now run derivatives of Linux (Android, Ubuntu, etc.) every day than use Windows.
Windows 10 is more friendly to Linux users than ever and here we explain how to install and use the Bash Shell, and some commands those new to Bash will want to try.
Jump straight to installing Bash
Not long ago Microsoft toyed with the idea of building its own Linux distro. That notion morphed into Project Astoria, a technology designed to enable Android apps to run on Windows.
Astoria was ultimately scrapped because it would have eliminated any reason for Universal Windows Platform (UWP) apps to exist. Instead, Microsoft took an alternative approach to provide some of the functionality overlap they needed, without delivering a full-blown branded Microsoft Linux solution.
Windows Subsystem for Linux (WSL) was designed with the cooperation of Canonical (Ubuntu) and provides a complete Linux subsystem for Windows 10, allowing command line compatibility through the Bash command shell. Just to be clear; this doesn’t allow applications that use the X-Windows GUI on Linux to run on Windows. Though, it is possible to redirect the graphical calls to an external X server, enabling some to run under Windows 10.
What it does out of the box is to run all the standard Bash commands that are either used directly at the command line or in scripts. Theoretically, it can run text-based tools built for Linux, and compile Linux source code into executables, or run interpreted code like Python, for example.
That’s enough Linux to do many of the typical computing chores that developers and system admins need to do every day in hybrid Windows/Linux environments.
Why install Bash on Windows?
The obvious question you might be asking is why not just run a complete copy of Ubuntu or another Linux flavour using a virtual machine?
While taking that path does offer X-Windows GUI compatibility, that’s also a much more resource demanding option than WSL. As the virtual machine will parallel many functions that Windows 10 already provides inherently.
With WSL Microsoft built a layered solution through a Linux-compatible kernel interface sitting between Windows 10 and the Ubuntu image Canonical provided.
Because of the way the WSL is designed as distro-agnostic, it’s probable that Microsoft will support other Linux flavours in the future.
With the WSL is working in the same code space as other Windows subsystems any Linux command, app or code can also work directly with the NTFS file system, without the need to define shared storage space for data to pass from one environment to another.
On the flipside, this facility is technically still in ‘beta’, and there may be code or commands that don’t work fully in the current release. Hopefully, these issues will be addressed as they’re revealed.
Depending on your specific needs, having a Bash command line on Windows 10 is either a wonderful thing or another feature you won’t use. Though, it does strongly hint that Microsoft is truly coming to terms with its place in the post-Windows world of computing.
How to install Linux on Windows 10
Your PC or laptop must have Windows 10 64-bit installed, and it must be at least the Anniversary Update (or a newer release). To install WSL you must first enter ‘Developer Mode’.
The switch for that is in the Settings app under ‘For Developers’. Apparently, developers are living dangerously by installing software that didn’t come from the Windows Store, warranting a warning confirmation before the mode is activated.
After this Windows 10 will suggest you reboot, but ignore that suggestion for now.
Microsoft still hasn’t come to terms with the idea of a single place for settings so the old control panel now needs a visit.
In Programs and Features you use the option to turn said features on and off, and if you’re in Developers Mode you’ll have some extra options including ‘Windows Subsystem for Linux (beta).
After ticking that, Windows will suggest you reboot, and this time around you should.
When Windows restarts it appears nothing has changed, mostly because little has. However, if you type ‘bash’ into Windows search, along with the dictionary definition of the word, an executable file called ‘bash.exe’ will, be listed.
Running this will bring up a command window to complete the WSL installation.
The executable runs a script that requires the inputting a ‘y’ to confirm WSL install. Once initiated the download process is reasonably rapid, and after completion you’ll be asked to provide a username and password.
For those using the Anniversary Update get ‘Trusty Tahr’ 14.04 LTS, and those on the bleeding edge of Windows 10 releases are rewarded with ‘Xenial Xerus’ 16.04 LTS version of Ubuntu.
Those desiring the signature Ubuntu experience can even go download the official monospace font for inclusion in Windows, and use in the shell.
Once the installation is complete Bash will get an icon, appear on the list of applications and be available to be launched in the myriad of ways Windows 10 allows.
Inside the Bash shell you can use ‘ls – alg’ instead of ‘dir’, along with all the other familiar Linux commands like grep, awk, sed, sudo, and so on.
You can even put Bash commands in PowerShell scripts, by putting ‘bash’ in front of them, as per – bash sudo apt install git.
But probably the most important command they included is ‘apt-get’ as it allows you to install software from the Ubuntu software repositories, just like any standalone Ubuntu installation.
Some Bash Commands to try
With WSL installed, you may want to try out a few commands in the Bash shell.
Lists the files in the C: drive, use ll /mnt/d if you want to see in D:
Details what release of Ubuntu the installation is using
sudo apt-get update sudo apt-get upgrade
Updates the package list from Ubuntu, and then upgrades those parts identified as already installed.
Launches the vi text editor, or you can try nano instead.
The commands ‘cd’ and ‘mkdir’ are the same in Bash as identical to those in Windows (DOS), where the copy command is ‘cp’, del is ‘rm’ and move is ‘mv’.
If you want a complete collection of supported commands any Linux reference will cover the majority, their command syntax and associated parameters.
It’s worth noting that Linux is case sensitive, and so when referencing files and folders you must use case accurate naming.