puppy technology

Bash on Windows

So, Microsoft released Bash on Windows. I installed the Windows 10 Anniversary Update and immediately started poking around.

Initial Impressions

It’s not as bad as I expected.

First, the good news: They updated the Command Prompt! It now supports most ANSI and VT100 escape sequences! This is fantastic, because the command prompt used to be an abysmal pile of failure.

However, there is one big problem I ran into with Bash on Windows: accessing the same file from inside Bash and outside of Bash can cause filesystem corruption.

In my case, I was using Bash and the Atom text editor. I found that when creating, moving, or removing directories, there would be frequent corruption. This manifested as directories which simultaneously showed up when running ls in the parent directory, but didn’t exist if you tried to access them.

From a comment on a GitHub issue for Bash on Windows:

Please DO NOT manipulate the Linux filesystem from Windows - this may well cause issues and/or corruption. It's fine to access your Windows filesystem from Linux, but the other way around is not a supported scenario at this time.

I documented the first encounter of this problem on Twitter, and the second encounter in a separate thread.

A Working Ruby Environment

Bash on Windows is based on Ubuntu 14.04, so it ships with Ruby 1.9.3 — which no longer receives even security updates. You’ll want an actually-supported version of Ruby. In my case, I just went with the latest stable version (as of August 11 2016, 2.3.1). I found my method of getting a working Ruby environment on Ubuntu 14.04 worked as expected.

For the rest of this I’ll assume that you will, as I do, use ruby-install and chruby, both by postmodern.

First, you’ll want to install the build-essential package. Just like as on Ubuntu, you can do this via apt-get install build-essential.

The typical ruby-install and chruby installation procedures both should work exactly as expected.

Be sure to add the required line to your .bashrc or .zshrc file, as mentioned in chruby’s documentation, so you can actually use chruby.

After that, the only thing left is to (optionally) set the default Ruby version you wish to use. This is as simple as adding chruby 2.3.1 (or whichever version you use) to the correct file. The chruby documentation says to use .bash_profile or .zprofile, but I found I had to use .bashrc or .zshrc.

And there you go. You should have a working Ruby environment in Bash on Windows.