Getting going with Bash on Windows
Patiently I waited, and you know what they say “good things come to those who wait”. When I first heard about the release of Bash on Windows (which is run via the Windows Subsystem for Linux, here is a great overview), I was so excited that you’d think I had nothing else going for me in my life (for the record, I do… I’m just easily excited by shiny things).
Like many, I began my programming years on UNIX, and spent over 10 years primarily working in a command line even while living out the “experience” that was Visual C++ with MFC (I originally said “horror” but ok it wasn’t all that bad - it’s just that the .NET Framework with Visual C# solved so many of the pain points from it that looking back now it seems like it may have been hell!). Anyway, my point is that I used to live in the command line, I love the power of it, love the scripting languages, and let’s be honest, using the command line makes us feel smarter! Come on, it’s true. I’ve tried to recreate the experience since moving to pretty much full-time Windows-based web development using tools like Cygwin, the Git Bash, and a lovely selection of “UNIX-commands for DOS” that I’ve been carting around for years (which seem to have stopped working in Windows 10, anyway), but it’s not the same.
Let’s be honest, using the command line makes us feel smarter!
Also from a development perpective, I know there are languages out there that just don’t run quite the same on Windows as their Linux counterparts (like Ruby), so yay for those developers who can now harness this system to solve that problem. Even running small business WordPress sites on a local Linux system will be helpful for me, because there are quite a few gotchas when moving from Windows development to Linux production server for WordPress.
The problem was, I’m on the Slow Ring for the Windows Insider Program, because after all I have to be a little sensible; this is my only PC now (not counting the iMac and gaming PC in my home office, because I don’t really want to have to “work” on either of those now), and if an update came out on the Fast Ring that broke stuff, I’d be in serious trouble!
So I waited patiently… and waited… and waited… and then yesterday my waiting came to an end as the Slow Ring got the 14342 build update, which includes 14316 and it’s subsequent patches (so hey, I also straight off get a “better” version than the original release of Bash On Windows).
Installing Bash on Ubuntu on Windows
Last night I got all the updates applied, ensured my system was set to Developer Mode for apps and added the Windows Feature for “Windows Subsystem for Linux (beta)”.
Then I went to bed and dreamt ALL NIGHT about typing commands into a bash shell (seriously, every dream was about it!).
So today my adventures have begun. First I installed Bash on Windows, the simple way I did this was just to type “bash” into Cortana and she found what I needed, ran that and the Windows command prompt opened, advised me that this would install Ubuntu on Windows, and asked me if I wanted to continue (yes, yes I do!). A couple of minutes later the download was complete, and I was asked to enter a new UNIX username and password (for information on this, check out this MSDN article):
All set, and I get thrown into my first “real” Bash shell on my Windows machine ever!
To access this quickly from here on, there is also a new app shortcut setup called “Bash on Ubuntu on Windows”, so hitting the Windows key and typing “bash” will get to that, or you can pin it to start or taskbar.
Using Bash on Windows through ConEmu
Personally I already use ConEmu, a Windows console emulator, for all my terminals (cmd.exe, PowerShell, Putty, Git Bash etc). So first step for me was to setup ConEmu for the new terminal. In ConEmu Settings, go to Startup > Tasks and add a new task, for now I’m just simply running Bash with the default directory being my UNIX home directory (~):
I’ve set it up in a new group “WSL”… because you know, in future we may have other things under that?!
Now I can bring up a bash console by simply running ConEmu (I use the “Quake shortcut”, Ctrl+~), and choosing it from the New Console Dialog menu, and I may well make it a default, as well:
A small bug I found was that my arrow keys weren’t working at all in Bash on Windows when running it through ConEmu (e.g. up/down to cycle through history), where it worked when running the Bash on Windows app standalone. I found this was a known issue, updated ConEmu to the preview version 160515 (at the time of writng this, the latest stable version was 150813g, and the workaround developed by the ConEmu team was in 160411), and updated my task to include a new switch:
%windir%system32bash.exe -cur_console:p1 ~
That fixed my arrows issue in Bash on Windows using ConEmu.
Installing Git - first use of apt-get
My next step was to use apt-get
for the first time on Windows…. first I grabbed Git. Helpful hint from Bash (not sure if this is thanks to Ubuntu or a customisation from the Windows guys?), try to run git
and it tells me exactly how to get it (no need to Google for the correct apt-get command). So run the apt-get command:
sudo apt-get install git
Off it goes grabbing and installing Git and some other related packages, and now I can run Git (ok so I could always do that on Windows - boring!):
A better shell - zsh
Over the years I’ve been a bit of a shell whore - I’ve used bash, csh and more recently zsh. I only started using zsh a couple of years ago, when I started my brief love affair with a Mac, because I read somewhere that zsh was better than bash, but I never really USED it and took advantage of its power. I saw in the release notes that zsh is now supported on Bash on Windows, so last night I went looking for reasons to use it, and boy did I find them. I had no idea how powerful and awesome zsh could be! Check out this fantastic slideshow for a rundown.
So to install zsh on my Bash on Windows, I ran the apt-get command:
sudo apt-get install zsh
Run zsh
to start up the shell and set it up for the first time (if all goes well I will change it to my default shell, but will run it through some tests first), I have chosen to use the “configuration recommended by my system administrator”, whoever that may be (!), and away I go:
bron@FRIDGE ~ %
So what’s next for me? I’m going to play around with zsh to see that everything that’s awesome in it works nicely (since it’s a relatively new feature of Bash on Windows), and then I’ll see if I can break the space-time continium by trying to install and run .NET Core on a Linux system running on a Windows system (fun!). Or at least get PHP on Apache working on it.