For Systems Administrators and Developers, one of the best features of a Mac is that it comes with a fully functional and well maintained UNIX-like command line environment (CLI). Right out of the box, the Terminal app gives you a bash shell and access to the typical UNIX software, such as ssh, rsync and python. You can also very easily add on Xcode for software development and Xquartz to launch graphical applications. It’s really great and has driven a lot of IT professionals to switch to Macs in recent years.
With the Windows 10 Anniversary update, Microsoft has finally decided to take a crack at providing that same functionality. The add-on is called the Windows Subsystem for Linux or WSL for short. Its available as a Beta™ feature that can be optionally enabled in Windows 10 after the Anniversary Update is applied. It was available before the update, but only to developers that were running Insider Preview builds of Windows, so it didn’t see much widespread use.
Personally, I do about two-thirds of my work computing on an iMac and the remaining third on a Windows 10 laptop. For years, I’d been using a third party utility, Cygwin, for the majority of my CLI administration and development needs while in Windows. Not long after the Windows 10 Anniversary update was released, I took the plunge and switched completely over to WSL.
Its been… eventful. Microsoft has obviously put a lot of effort into making WSL work well and it shows promise that it will be a comprehensive solution, but it’s definitely beta quality software and has more than a few hiccups at this point. It’s fairly easy to get installed and going, with most things just working, but after a while you start to notice some missing functionality and general awkwardness. As usual, there are workarounds for most of the issues, but they can require a significant amount of time to figure out and implement.
Below, I’ve outlined how to setup and use WSL on a Windows 10 PC, along with some of the workarounds I’ve found necessary
Following installation, you’ll have a basic Ubuntu Linux command line environment, with all of the typical tools available. Most of the usual Linux commands apply here, but there are some interesting areas, particularly where Windows integrates (or doesn’t) with the Linux environment.
By default, the terminal runs as a normal, unprivileged user that does not have root (administrator) access. Confusingly, this occurs even if you launch the terminal as a (Windows) administrator. To access the Linux administrator account, you’ll need to switch to the root account via the su command in bash, or prefix your commands with the sudo command. For example if you wanted to edit the /etc/example.conf file as root: sudo vi /etc/example.conf
Instead of sitting directly on top of Windows’ filesystem, like cmd.exe does, WSL programs run in a nested environment. For example, your home directory in the bash environment is completely separate from your Windows home directory.
To access files in the regular windows filesystem when running a Linux program, you’ll have to navigate to the appropriate drive letter in the /mnt/ directory. For example: ls /mnt/c/Users/brian.camp/Documents . That’s obviously less than ideal if you need to regularly work on the same files in both the Linux and Windows environments.
This configuration also means that if you have ssh keys that you will be using, you will need to copy them from where you store them in Windows over to your Linux home directory.
Unfortunately, the terminal used by WSL is the same as cmd.exe, which is pretty primitive compared to what you would see on a Mac or Linux desktop.
Hopefully, this is something that is improved with a future update. It’s pretty disappointing to have to reach for the mouse to paste text and such.
The system uses Ubuntu as its base and includes Ubuntu Linux’s own package management to handle software, rather than Add/Remove Programs and Windows Update. Since there is no GUI available by default, you’ll need to have a passing familiarity with the apt-get command to update existing packages and install new ones.
For some reason, the “Bash on Ubuntu on Windows” shortcut launches bash as in a non-interactive mode by default, even though it is obviously designed to be used interactively. This is actually OK for most things, but can cause issues with some tasks and makes customization of the shell difficult.
To make bash launch in an interactive mode, also known as a login shell, you need to modify the arguments the shortcut is invoked with. To do that –
X11 / GUI Applications
By itself, WSL is only capable of running text-based applications, which is its primary purpose after all and fine in most cases. Plenty of GUI applications are available to be installed via the built-in apt-get command though, but none of them will work unless a 3rd party X11 server is installed and some system configurations are modified.
The setup is less than ideal. Hopefully, Microsoft will bundle their own integrated X11 server in a future version of WSL.
Xming (X11 Server) Setup
To add on GUI support, you’ll need to install a X11 server and configure WSL to use it. There are several X11 servers available for Windows that are known to work with WSL, and I used Xming I particular in my example.
Many X11 applications require D-Bus to function properly and the stock configuration of WSL will not allow D-Bus to run. You may see some applications giving errors regarding d-bus or simply crashing.
Thankfully, there is a simple workaround.
Overall, I think that Cygwin is a better solution right now, but have kept on using WS, because I think that it’s likely Microsoft will continue to improve it.