Install Linux on Windows
Try it without the hassle: step-by-step guide
When Windows 10 was first announced, Microsoft promised that regular updates would add new capabilities. Few of us imagined that this would include a fully functioning Linux environment, but that’s exactly what we got in last year’s Anniversary Update.
To be precise, the Windows Subsystem for Linux – WSL for short – isn’t a consumer-oriented graphical distribution like Ubuntu. However, it contains all the underpinnings needed to run a Linux bash shell (the user interface) on your Windows PC. You get full access to the default Linux tools, and you can install software directly from the Ubuntu repository.
With a bit of technical wrangling, it’s even possible to run graphical applications directly on the Windows 10 desktop, as we’ll discuss. This isn’t really what WSL’s intended for, however: in Microsoft’s words, the subsystem is “aimed at enabling users to run bash and core Linux command line tools on Windows. WSL does not aim to support GUI desktops or applications.” If you want to run Linux apps on a day-to-day basis, it’s probably a better idea to run a mainstream distribution inside a virtualisation host, such as Hyper-V – which is built into Windows 10
Professional – or the free VirtualBox hypervisor ( virtualbox.org).
If you just want to run the odd tool or write the occasional script, however, WSL is the perfect choice. And, because it’s part of Windows, all your files are immediately accessible within bash – something that can be a pain to set up with virtualisation.
At this point you might be wondering what the arrival of WSL means for PowerShell, Windows’ own scripting, management and remote control utility. The answer is the two are designed to co-exist. Officially, WSL is aimed at developers who work with open-source projects, but otherwise work largely in Windows. It will also appeal to macOS power users, since the bash command line interface is extremely similar to Apple’s Unix-based Terminal.
GETTING AROUND IN LINUX
If you’ve never used Linux before, you’ll have a few new commands to learn. Type “help” to pull up a list of built-in commands, many of which will already be familiar (“dir”, for example) or obvious (such as “logout”). The principles of Linux are similar to working with the Windows command prompt, but there are a few philosophical differences.
One is that the Linux file system isn’t focused on discrete drives like Windows is. To see this in practice, simply open bash and a Windows command prompt side by side and navigate to the root in each, by typing “cd \” in command prompt and “cd /” in bash. You’ll notice that command prompt takes you to the top level of your hard drive (that is, C:\) while bash steps out of the drive altogether, and locates you at the root of the overall file system.
Your current directory is displayed at the end of the prompt: for example, if you see “yourname@WINDOWS10:/ usr/local$”, that indicates that any commands you enter will impact or execute the contents of “/usr/”local. If this simply shows “~$”, you’re in your own home folder. If you want to switch to a different drive, you’ll find your physical volumes inside the “mnt” (mount) folder: to get to the C drive, type “cd /mnt/c”.
Another difference is that while Windows doesn’t care about cases, Unix-based operating systems do. So, while “cd documents”, “cd Documents” and “cd DOCUMENTS” would each take you to the same place in the command prompt, they refer to different folders in bash – and if you have a folder called “Documents” it won’t be found if you enter “cd / documents”. Special characters such as spaces are handled differently, too: “cd Program Files” works fine in the command prompt, but in bash you must “escape out” the space by preceding it with a backslash, thus: “cd Program\ Files”.
There are some neat conveniences in bash. The “dir” command lists your files and folders on both systems, but bash has an extra trick. Use “dir -color”, and the results are colourcoded to make directories (blue) easy to distinguish from files (green). As in Windows, you can repeat previous commands by simply pressing the up cursor key multiple times to scroll through your history. You can also type the first few characters of a file or folder name, then hit Tab to have it automatically complete.
USING BUILT-IN TOOLS
One of the best-known Unix tools is vim, a text editor that’s been knocking around since the 1990s (and which is based on an editor called vi that was originally released way back in 1976). It’s commonly used for scripting, as well as regular text work. There’s no graphical interface, but its keyboard commands are straightforward to learn, and you can also enable basic mouse control.
To try vim, start by navigating to your Documents folder: for security reasons, Linux limits your ability to make changes outside of your home folder. In our case, we’d achieve this by entering “cd /mnt/c/Users/nik/ Documents” (substitute your own Windows username for “nik”). Then, enter “vim”, in lower case, followed by the name of the file you want to edit: for our purposes, we’ll enter “vim test.txt”, which will create a new file called
TEST.TXT, or open the file for editing if it already exists.
When vim opens, it will be in Command mode. To enter text, you must switch to Insert mode by pressing “i”. You can then immediately start typing into your document (you don’t need to hit return after the “i”). You should notice that the bottom line of the interface now says “INSERT”, and will stay like that the whole time you’re in this mode.
When you’ve finished entering your text, press Escape to return to Command mode. If you’ve written all you need, you can save the file and exit by typing “ZZ”. If you want to quit without saving, instead enter “:qa!”. Clearly, vim’s commands can be quite cryptic: luckily, you’ll find a useful cheat sheet at vim.rtorr.com.
One command worth knowing about is “:set mouse=a”, which makes the mouse active. This lets you click to move your cursor around within the document, rather than having to navigate through the keyboard instead.
While WSL comes with a good set of default tools, its full potential lies in the ability to install additional apps. This is very easy to do: bash can download software automatically from the Canonical repository using the apt-get command (it stands for Advanced Package Tool). As an example, let’s install Lynx, a textbased web browser that was popular during the early days of the internet. Installing software must be done by a “superuser” – the equivalent of an administrator in Windows – so we use the “sudo” (“superuser do”) command to authorise it as follows:
sudo apt-get install lynx-cur
After entering this command, you’ll have to enter your password to authorise the installation. Once it’s installed, you can test it by typing “lynx bbc.co.uk” to navigate to the BBC’s website. Select links using the arrow keys, and hit return to follow them. Naturally, being a text-based browser, the pages are stripped of their images and styling, so they load very quickly. To navigate to a different page, press “g” and enter the address. Pressing “delete” lists your history, and “q” quits the app.
To remove an application, you can use the same command – simply replace the “install” argument with “purge”:
sudo apt-get purge lynx-cur
Another use for apt-get is keeping applications up to date. After all, just as in Windows, it’s important to install patches and security updates as they become available. Happily, it’s very easy to keep on top of this: each time you launch bash you’ll be warned if updates are available, and when you’re ready to install updates you can update everything at
once by simply entering: sudo apt-get update
RUNNING GRAPHICAL APPLICATIONS
As we’ve noted, Microsoft doesn’t currently intend WSL to be used as a host for graphical apps. But that doesn’t mean you can’t do it – you just have to go to a little more effort to get them working. Follow these steps:
1 Start by installing an X server. X is the window manager that handles Linux’s graphical front end. There are plenty of X server systems, but we’ve opted for VcXsrc ( sourceforge.net/projects/vcxsrc). Install it, then launch it from the Desktop or Start menu. Choose to start it as multiple windows.
Install the graphical application you want to use. We’re using AbiWord ( abisource.com) –a free, open-source word processor. You can install it using apt-get in just the same way we did with Lynx: sudo apt-get install abiword
We now need to tell the Linux subsystem where to display the graphical application, since it doesn’t yet know about our X server. This is again performed by issuing this command and hitting return: export DISPLAY=:0
(Note that the last character is a zero.)
Launch AbiWord by typing “abiword” at the bash prompt (all lower case). The app should now open in your X server window. It’s not a perfect implementation: saving can be a bit fiddly, as sidebar locations such as Home and Desktop are inoperable, but if there’s a graphical Linux application that you can’t live without, running X on WSL could be your simplest option.
Once you’ve given WSL a go, you may decide it’s not something you need to use regularly – or you’d prefer a full graphical Linux installation running inside a virtualisation host. Either way, you can remove the Linux layer and reclaim some disk space: first, close bash; then open the Windows Command Prompt and enter: lxrun /uninstall /full
You’ll be prompted to confirm that you’re happy to lose all of your Linux applications and data. The entire WSL system will then be removed.
WSL remains in beta, and there’s still no authoritative documentation. For more information, start with the FAQ on MSDN: pcpro.link/274wsl.
There’s a lot more information available around the built-in Linux commands. For a quick guide, use the “-help” switch to show available options: for example, “dir -help” shows how to tailor the output of a directory view. For comprehensive documentation, use the “man” (manual) command: entering “man vim”, say, will bring up an extensive 19-page guide to vim. Press “q” to exit the manual reader.
RIGHT The text-based Lynx browser is fast, partly because it ignores images and advanced text styles
RIGHT The vim text editor is a popular development application, and is installed with WSL by default