Rapture in Everything

Ruby on Bash on Windows


While in the process of migrating this blog, I've made some modifications to the Scrawl theme by Kate Preston. It was written in Sass, which I didn't have installed at that moment, and didn't want to deal with it - so for a while, I just manually edited the CSS. That, of course, got annoying quickly.

The main reason I didn't want to install Sass was that it required Ruby; and last time I've tried using various Ruby libraries on Windows, it was a lot of hassle and no results. All pain, no gain, so to say.

But since then, Microsoft had released the "Windows Subsystem for Linux", colloquially called "Bash on Ubuntu on Windows". In case you don't know about it, it's been added to Windows this summer, and it's a full, normally running Ubuntu image. It's not emulation - Canonical worked with Microsoft, and they provided a subsystem that connects the running Linux to the underlying Windows kernel. The result is that you can use both Windows and Linux tools to work on the same, live system. No more faffing about with Cygwin and the like, yay. It also means that you can now run unmodified ELF binaries and use the apt-get package manager, for example. (In case you're wondering what's Windows' recommended package manager, check out Chocolatey.) Considering this, I decided to give Ruby another chance.[1]

I just started Bash and immediately did apt-get install ruby, then gem install sass. Both worked without a hitch, but when I ran Sass, it complained I'm using Ruby 1.9, and I really should switch to 2.0+. Figuring I might as well do it right while I'm at it, I decided to upgrade.

I've tried many things, including uninstalling the Ruby package, installing the 'ruby2' package, etc. (Interestingly, the Ruby2 package installed, but the subsequent ruby -v check still said I'm running 1.9. And no, I didn't have the ruby executable pointing to a forgotten, older version; I've checked.)

So I took a deep breath, uninstalled everything again, and decided to compile the latest Ruby from source. I've found a handy how-to here, updated the URLs to point to the latest source version, and ran this:

sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar -xvzf ruby-2.3.1.tar.gz
cd ruby-2.3.1/
./configure --prefix=/usr/local
sudo make install

After it ran to completion, I've tried running Ruby again - the executable was not found. which ruby told me Bash is looking into the wrong place - where the original installation has been. So I ran hash -r to make Bash forget all of the previously located binaries. When I tried again, Ruby was up and running. I've installed Sass again and checked the versions. No complaints this time.

> ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
> sass -v
Sass 3.4.22 (Selective Steve)

With the newest tools installed, I've tried to do the work I've actually wanted to do from the start. Everything went without a hitch. Even the sass --watch, which watches for changes in file system and automatically rebuilds the source, worked quickly and correctly.

Overall, I'm impressed by how well the entire Linux Subsystem / Bash on Ubuntu on Windows works. I know these were not the most demanding tasks one could try, but they do cover a lot of common use-cases, and the fact that I can now work with native Linux binaries on Windows is so cool.

  1. And look: I've even managed not to call this post Sass on Ruby on Bash on Ubuntu on Windows. It wasn't easy, though. ↩︎