The Unixian's Guide to Windows
A few hints for users coming from the UNIX world to find their bearings when they get to work on Windows systems, maybe even to almost feel right at home.
And when I say UNIX I'll be referring to Linux most of the time. It's just that especially compared to Windows, the difference between Linux and other UNIX flavours is insignificant. Funny actually how I naturally gave this post a title sounding like The Hitchhiker's Guide to the Galaxy, as Windows may feel like going on holiday to another galaxy to UNIX people. And it's equally true for Windows users giving UNIX a try, let's be honest.
1 PowerShell Has a Vi Mode!
Now before you try to make look Windows as much as possible like UNIX, it's probably worth giving PowerShell a go. It's not bad at all as a shell, and I really started liking it when I discovered it's got a Vi mode enabled as follows:
Set-PSReadlineOption -EditMode vi
Next thing you'll want is to have PowerShell do this every time you start it. Simply add the above command line to your Documents\WindowsPowerShell\profile.ps1
.
2 Vim
But how do you edit your profile.ps1
without a decent editor? Yes, there's the Notepad, but it's not exactly what I mean by decent. As it turns out there is an official build of Vim for Windows. It's quick, non-intrusive, and brings a lot of UNIX happiness to the Windows world. That's because it's far more than an editor: you can use it for browsing files, munging data, running commands – although they're going to be Windows commands obviously, the same ones you'd type in a Command Prompt. Before long, with or without Vim, any Unixian is going to miss the rest of the UNIX toolkit.
3 Cygwin
Since 1995, Cygwin has been acting as a salvatory hand for distressed Unixians using Windows. UNIX is not all about stability, reliability, security and Windows has in fairness improved on all these fronts over the years. UNIX is also about a set of utilities users have learned to know and love. I mentioned Cygwin before when I explained how to go about Remotely Executing Processes from Files.
I remember my first encounter with Windows 10, which had been dismal. A friend of mine asked me to tidy up terabytes of her pictures scattered all over the shop in disks, SD cards and USB sticks. The Windows user interface being what it is, progress was slow and made even worth by the fact that file copies randomly and silently interrupted themselves the moment you attempted to perform two or three tasks at the same time. Interestingly, Cygwin saved me from at least that as rsync could perform the same copies much more reliably. Interesting how it's not even the underlying Windows system that broke, but just its GUI. Did I mention I dislike GUIs?
Installing Cygwin is straightforward and involves installing a set of tools of your choosing along with it. It's probably worth noting that I've often been more successful using HTTP mirrors rather than the FTP ones to download the packages, for some reason or other. For your first installation, it's probably reasonable to just leave the default package selection as it is.
The most natural entry point to Cygwin is the Cygwin64 Terminal (64 if you installed the 64-bit version, of course) which has become accessible in the start menu (perhaps even on your desktop if you let the installer do so). It brings you to a bash command-line interface where you'll immediately find a more familiar environment. What you'll want to work out soon enough is where you actually are. Running pwd
suggests /home/yourusername
but it's got in fact nothing to do with C:\Users\yourusername
. In fact your Windows files are accessible in Cygwin from the /cygdrive/c
directory. Conversely, Cygwin files are accessible in Windows from the C:\cygwin64
directory.
There's a surprising amount of packages available in Cygwin and installing new ones entails launching the setup-x86_64.exe
you installed Cygwin from the first time round. In fact, it's going to feel like you're installing Cygwin all over again as the procedure is exactly the same but fear not, the installer is clever enough to notice that you've already done so and will only install the new packages. It'll even remember the mirror you last chose. It should become clear by now that the setup file is a useful one to keep at hand.
Note that installing Cygwin doesn't mean installing a UNIX system into your Windows. It just means installing typical UNIX tools built to run on Windows. Take a look at the contents of C:\cygwin64\bin
for a funny sight: you'll see a wealth of familiar executables such as chown
, ls
, whoami
, etc., but with an incongruous exe
extension. So if they're just Windows executable, can we run them from PowerShell? Absolutely, and you might even want to go as far as having them in your path by right-clicking on This PC → Properties → Advanced system settings → Advanced tab → Environment Variables..., double-click the Path
user variable, hit New, then Browse... to locate your Cygwin bin
directory (e.g. C:\cygwin64\bin
).
4 Windows Subsystem for Linux
Microsoft have become good. Really good. I can't believe I've just said that, I certainly wouldn't have believed that I ever would when I was young and zealous. (I'm still young, just no longer zealous.) If Cygwin doesn't install more than UNIX tools, a step closer to installing a UNIX system inside Windows is the Windows Subsystem for Linux (WSL) available since Windows 10. This insane feature provides a Linux-compatible kernel interface (not the Linux kernel itself, though) which enables you to run Linux binaries.
The Microsoft documentation is up to a point self-explanatory for Unixians. Note in particular that they state that the Enable-WindowsOptionalFeature
command must be run as Administrator, which means right-clicking on the PowerShell icon and choosing Run as administrator:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
No, there's no sudo
command that you can run inside the PowerShell. Don't get carried away. Yet. Once this command has completed, let it restart the system. Interestingly, none of the following steps require administrator privileges anymore.
What follows is a bit of a faff if you stick to the official documentation. Using the Microsoft Store will obscurely be met with variable success rates depending on your configuration and the problem is that failures aren't followed up with informative error messages. They aren't followed up with any messages at all in fact. So let's stick with the UNIX way of doing things, let's use the command-line interface since Microsoft was generous enough to explain how in their Manually download Windows Subsystem for Linux distro packages instructions. You can choose from various Linux distributions to run in the WSL – I'm going for Ubuntu 18.04, here:
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.appx -UseBasicParsing
That's what we Unixians would have done with curl or wget. It'll write the Ubuntu.appx
to the current directory. While you can run it directly, doing so will probably involve some component or other of the Microsoft Store software and we've seen before it's not good at it. Since an APPX file is nothing more than a ZIP file, let's unpack it as suggested in the Windows Server Installation Guide – yes, Windows Server. This is fine, it appears to be the most reliable approach for all flavours of Windows, Server or not:
Rename-Item ~/Ubuntu.appx ~/Ubuntu.zip
Expand-Archive ~/Ubuntu.zip ~/Ubuntu
Yes, you do need to rename the archive first, because Expand-Archive
is a bit daft and will not look past the extension to find out that it's actually something it can work with. The extracted files will include a ubuntu1804.exe
file and running this will ask you to offer a new username and password for a UNIX account in the WSL before landing you in a bash shell. Is that it? Yes it is, and to convince yourself, go ahead and run for instance:
sudo apt update
Yes, that's Ubuntu alright, then. You may not want to have to every time open PowerShell to then start a shell in WSL. Simply starting ubuntu1804.exe
from the File Explorer will open the shell in a window of its own and, more interestingly, display an icon of its own in the task bar for you to pin for any subsequent use.
What a time to be alive. Microsoft have actually willingly brought Linux to Windows and done a fantastic job to open the doors to the best of both worlds. Or have they? Well, after the rush of excitement you might realise it's not all that wonderful after all. You may experience your shells not to be as responsive as if they were run by a real Linux kernel for one thing. And you will still not be able to access files from multiple programs simultaneously as freely as you want. Also, you're still stuck with the Windows window manager. Frustratingly enough, you've now got access to all the Ubuntu repositories, you can choose from dozens of window managers and find the one you know and love but you haven't got an X server. It's still Windows under the hood at the end of the day.
5 Xming and Window Managers
Some independent publishers have developed X servers for Windows and a popular one is Xming. While it's become proprietary and the official website will request authentication to download the binaries, the original free releases on SourceForge are still available. Questionable as to whether or not you want to invest any time on it as I have done, when free alternatives such as VcXsrv and even Cygwin/X – none of which I've tried out yet – are on the rise.
Anyway, back to Xming. Once installed and started, go ahead and run in WSL:
sudo apt install x11-apps
DISPLAY=:0.0 xclock
... and behold! An xclock in its own Windows window! So how about running a full window manager?
sudo apt install fvwm
DISPLAY=:0.0 fvwm
Sadly, FVWM will complain that another window manager is already running. And that'll be Microsoft Windows'. But more specifically, it's also because Xming was (by default) started in Multiple windows mode. To change that, locate the Xming icon (which my be hidden) in the task bar, right-click on it and exit it. Then, open the start menu and instead of starting Xming, start XLaunch which will let you decide how to have it display X clients. Pick One window → Next → Start no client →Next →Next → Finish and you'll see the familiar grey empty moire display waiting to be filled up with your X clients.
Back in the WSL bash shell, run DISPLAY=:0.0 fvwm
again and you're good to go. Now, that's already something but it doesn't solve everything – you won't be able to have your File Explorer or Word windows managed by FVWM. This could be suitable if you spend a sizeable time working with graphical Linux applications, including tons of terminals. But if you need to juggle between Windows and Linux applications all the time, the stark separation between the two worlds could fast become annoying eventually.
6 Outlook
Not Microsoft Outlook, I know we're on the subject, but no. I should have called this section Conclusion, or something. Anyway, there is plenty of Windows software nowadays to make Unixians feel more at home and it's remarkable that Microsoft made that wonderful gesture of bringing Linux distributions to Windows. They had to, I suppose, mind you – we had Wine for decades. But there is still some way to go, certainly, what with the fact you still can't run custom window managers on Windows, you're still constrained with a system that sets unreasonable limits such as not being able to simultaneously write to the same file and I'm not talking about those rough edges which make your Linux interface drag on or otherwise misbehave. But a few years ago, I'd never thought we'd come this far already. So let's wait and see, now that we know nothing's impossible.
7 References
- Windows Subsystem for Linux on Wikipedia
- Windows Subsystem for Linux Installation Guide for Windows 10 – Official Microsoft documentation
- Manually download Windows Subsystem for Linux distro packages – Official Microsoft documentation
- Windows Server Installation Guide – Official Microsoft documentation
- Xming X Server – Official Xming website
- Xming X Server for Windows where you can download free releases of Xming
- VcXsrv Windows X Server
- Cygwin/X