Giving WSL a Bash

The Fall Creators Update makes the Bash on Ubuntu on Windows on Laptop on Desk feature accessible to all

Lee Machin
LGTM
6 min readNov 20, 2017

--

I went to a hell of a lot of effort to create the Windows 10 UI in Xmonad… 😜

I think they just say it’s better to call it WSL and you’re running a specific distro now, but whatever. The ecosystem around the subsystem is substantially better than it was this time last year, when the whole thing was in beta. With that in mind, let me tell you how you can get the most out of your new Linux environment as a Windows user.

Step zero: for old Beta users

Uninstall your old setup that relied on the lxrun utility and install the new version of your distribution from the Windows app store (just search for Linux). I noticed a palpable increase in performance after doing just that, and your legacy environment will no longer receive such updates.

Step one: Get WSLtty

How do you even pronounce that? I know how developers love to turn acronyms into words, like how MySQL is actually MySequel (yet PostgreSQL is Postgres presumably because PostgreSequel is a mouthful), but talking about downloading and setting up weasel titty is going to sound perverse at best and disturbing at worst, particularly if you’re talking about how much it sucks.

Anyway, download it and run the installer. It’s the cleanest and most functional console app I’ve found that just gets straight to the point. I’ve also found that mouse support is much better, in the sense that it actually works.

If you want something more fleshed out that can run multiple different shells, you can’t go too wrong with cmder. It’s portable, so set it up in your Dropbox folder or a USB stick and you’re good to go on any Windows machine. You will have to take extra steps to get the bash side working nicely, though, and most of the help you’ll need is in this particular GitHub issue.

I gave Hyper a shot out of simple curiosity and while it’s a very sweet looking app and is super simple to configure, it can absolutely kill the performance of your laptop. I wouldn’t recommend this option unless you’ve got the hardware to balance that out, especially if you’re running Slack and Chrome and VS Code or Atom as your editor.

Step two: Configure your environment

You’ve probably got your dotfiles set up somewhere already and know what you’re doing with them, but if you haven’t you might want to do a bit of tweaking on the default setup.

Quick aside: Weasel Titty itself doesn’t support panes, so if you don’t want to run multiple instances you’re better off getting tmux installed, or making a bit of extra effort with cmder which does support that.

One of the big selling points of WSL is the interoperability between your Linux environment and your Windows environment. There are some subtleties to this that make it less seamless than you think it is, and if you plan to just use WSL for editing and not just running build and deployment tools you’re going to have to take some extra steps:

  • Anything you want to work with from a Windows app has to be saved somewhere in /mnt/c, which is how the Linux side sees C:\. For example, /mnt/c/Users/Beefcliff/Desktop is your Windows desktop. If you fail to do this and save in your $HOME directory, you will seriously fuck things up. The Linux file system is deliberately obscure and hidden by default in order to make this harder to do by accident.
  • If you use Git and use Windows tools for interacting with it, you need to configure them with autocrlf = true. This is so Windows doesn’t re-commit your entire repo and fill all of your files with ^M symbols for people working on Mac or Linux (or whatever Unix).
  • Similarly, configure your Windows text editor to use Linux style line endings (\n) if you can. Most editors will allow you to configure this and will do the hard work behind the scenes.

Step three… point one: Tmux, Vim, Emacs edge cases

If, like me, you want to live inside the terminal and you use tmux, you will need to make one change in your configuration that will make life much easier for you. I only discovered this after totally reinstalling the subsystem and setting up again, and realising that the issue only happened while inside tmux.

I’m going to spoil you with the solution before explaining why it matters.

Without this, you might wonder why your editor is doing weird things when you switch from insert mode to normal mode. I use Evil inside emacs and if I was lucky I’d get an error about an unknown keybinding, but otherwise some weird stuff would happen inside the buffer and it’d be difficult to undo it.

I thought it was because of the terminal because emacs and vim behaved the same way. Turns out that tmux by default sets a 500 millisecond delay when you hit the escape key, which is far too slow for any decent typist.

Step four: Make GUI apps work

With very minimal effort you can go one step further and run entire Linux GUIs from the subsystem. This is not officially supported but it works pretty well anyway.

If you don’t use it already, I recommend you install Chocolatey from a Powershell console and then run choco install vcxsrv. It’s a Windows X server and it will do all of the heavy lifting for you. If you run it as a full screen window you can actually go as far as installing a tiling window manager and replacing the Windows UI for the most part!

But to keep it simple, once you’ve installed that and got it up and running, just add one simple line to your shell configuration (.bashrc , .bash_profile, or whatever):

Reload your shell or source the file and you will be able to run your favourite GUI apps with relative ease. If you’re unhappy with the Windows terminal offerings, this means you can write a script on the Windows side to launch the Bash terminal, open up your Linux terminal of choice, and then hide that initial window that opened. Consider that a challenge and an adventure of your own, should you choose to accept it.

Wrapping up

That should give you enough to get started with Bashing up your Windows machine, opening you up to a whole new world of tools and resources that previously lingered just out of reach.

I use this productively in my day to day work as a developer, with few disadvantages compared to how I worked on my old Macbook. It is genuinely a boon and a huge incentive to give Windows another chance, particularly if you have other motives for using it (*cough* games).

PS: Sharing Configuration

It’s a common practice for people to store their dotfiles on Github and share them. I once did this but after Keybase released support for encrypted git repositories, I transitioned to that. This was mainly out of practicality, so I could store my API keys in there and automate that part of the setup.

However, if you like what you saw in that screenshot right at the start, I’m using Nord theme, the various parts of which you can find here:

The rest is fairly vanilla.

--

--