Blog

Share this Post:

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

Installation

  1. On your Windows 10 PC, make sure you have the Anniversary Update installed. The easiest way to do this is to simply apply all available updates (Start -> Settings -> Updates & Security), but a step by step guide can be found over at this blog post.
  2. Enable Developer Mode in Windows. Currently, WSL is only listed as an available when Developer Mode is enabled.
    1. Navigate to developer settings (Start -> Settings -> Updates & Security -> For Developers).
    2. Set the Developer mode radial.
    3. Reboot.
  3. Enable the Windows Subsystem for Linux feature.
    1. Navigate to Windows Features (Start -> Settings -> System -> Apps & features -> Programs and Features -> Turn Windows features on or off).
    2. Enable Windows Subsystem for Linux, near the bottom of the list.
    3. Click OK to kick off the installation.
    4. Reboot when prompted at the end of the installation.
  4. Now it’s time to setup the Ubuntu Linux bash environment itself.
    1. Open up a command prompt (Right click Start -> Command Prompt).
    2. Type “bash” at the command prompt and press enter, which will kick off the initial setup.
    3. Provide a username and password when prompted. This username and password is separate from your Windows login and will primarily used for in conjunction with the sudo and su commands.
  5. Locate the “Bash on Ubuntu on Windows” program in the start menu and click it to launch the environment.

General Usage

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.

Administrator Access

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

Filesystem Access

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.

Terminal Usage

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.

  • To change terminal options, such as the font, right click the title bar and select Properties.
  • To copy text from the terminal to your clipboard, highlight it using the left mouse button and then right click on the selection.
  • To paste text into the terminal, right click somewhere within the text area.

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.

Package Management

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.

  • To update the system to the latest release, run sudo apt-get update followed by sudo apt-get upgrade.
  • To install a new package, run sudo apt-get install <package name>. For example: sudo apt-get install tmux
  • To later uninstall a package, run sudo apt-get remove <package name>. For example: sudo apt-get remove tmux

Login Shell

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 –

  1. Locate “Bash on Ubuntu on Windows” in the Start menu.
  2. Right click it and select Open File Location.
  3. Right click the “Bash on Ubuntu on Windows” shortcut in the window that pops up and then select properties.
  4. Add “ -l” at the end of what is in the Target: box. So C:WindowsSystem32bash.exe ~ would become C:WindowsSystem32bash.exe ~ -l
  5. Click OK.
  6. Test and verify that you can still open new terminal windows.

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.

  1. Download and install Xming from the Xming project page. The defaults in the installer are fine.
  2. After installation is finished, launch Xming from the Start menu.
  3. Open a bash terminal and edit the .bash_profile file with an an editor such as vi or nano. For example: nano .bash_profile
  4. Add the following to the bottom of the file DISPLAY=localhost:0.0
  5. Save the file and close the terminal.
  6. Open a new bash terminal and install a GUI application. A very simple app that’s good for testing is xeyes, which is in the x11-apps package. For example: sudo apt-get install x11-apps
  7. Run the GUI application from the terminal to start it. Just run xeyes if you went with the x11-apps example.

D-Bus Configuration

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.

  1. Open a bash terminal.
  2. Using sudo, open the /etc/dbus-1/session.conf file with an editor, such as vi or nano. For example: sudo nano /etc/dbus-1/session.conf
  3. Find the line that reads: <listen>unix:tmpdir=/tmp</listen>
  4. Change it to: <listen>unix:tmpdir=/tmp</listen>
  5. Write the file.
  6. Close and re-open any bash terminals you have open.

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.