Wednesday, June 22, 2016

Giving Linux in Windows a bash – Part 2: How-to

So you want to tool up your Windows 10 install to include the Linux bash shell, eh? Have dreams of natively running compiled Fortran programs in a terminal window on the same PC that you use to craft your PowerPoint slides? Want to make GMT figures and then edit them immediately in Adobe Illustrator? (You say yes and yes? Are you me?) Well, I've started to figure these things out, and I'll share with you how I did it...

[Almost all of this could be cribbed from other places on the web, if you can be bothered; this is blog post is more of a compilation. If you want to track things back to the original sources, this is where I found instructions for changing to Insider Previews; I used these suggestions to try and get Windows Update to work with the previews; I downloaded a working ISO file for a suitable update here; this Microsoft blog showed me how to activate the bash shell; I found out about configuring the X server here; and there was also a subreddit with some useful background.]

1. Update to a suitable build of Windows 10

The bash shell interface is set to be included in the Windows 10 Anniversary Update, which is rumoured to be released in July. Since it isn't out yet, you will have to update to a 'preview' (read, beta) build of Windows to do that. All builds after version 14316 have bash included as an option, so go for one of those.
  • To check your operating system version, you need to take a short trip into the settings:
    • Click on the start button and then on the 'Settings' icon.
    • In the window that pops up, click on the 'System' icon.
    • From the sidebar menu that appears, scroll down and click on 'About'.
    • On the screen that appears, look for 'OS Build' and the number that goes with it. If it is above 14316, you don't need to do anything more here. 
      The Insider Program website. Yesterday.
  • If it turns out you do need to install a newer build of Windows, you first need to join the 'Windows Insider Program'. This is associated with your Microsoft account, and so you'll need to log in to Windows using it from here on in, if you aren't already.
    • Go to the Insider Program website, (pictured, right) and answer the questions there. It's free to join. 
    • Make sure you're logged into Windows with your Microsoft account.
  • The next step is to enable Insider Previews inside Windows. This requires some changes to your settings. 
    • Click on the start button and then on the 'Settings' icon.
    • In the window that pops up, click on the 'Update and Security' icon.
    • From the sidebar menu that appears, click on 'Windows Update'.
    • Then click on 'Advanced Options'.
    • Scroll down on the screen that appears, and click on the button that says 'Get Started' under the heading 'Get Insider Builds'.
    • A slider will appear with three positions, representing different levels of involvement. I chose 'Slow' – this means you only get preview builds that have been reasonably stable under testing. (If you like to live life on the edge, and can handle the possibility of the occasional less-vetted, unstable update, choose 'Fast'.) After a quick restart of your computer, you should now be ready for updates... 
In my case, having followed all these steps and restarted, I checked Windows Update, hoping to see details of my new version, and... nothing. Some searching of the Internets suggested that in some cases (but there was no firm sense for which cases), Windows needs a little prompting to turn up those updates:
  • It may be that your Windows registry needs some 'adjusting'. This site has some suggestions about various hacks you can try. I tried all of them, including the suggestions found in the comments. They didn't seem to do that much good for me, but your mileage may vary.
In the end, I decided to update Windows manually using an ISO file (DVD image) of one of the preview builds: 
  • Download a preview build from Microsoft's website. (The link is for build 14342, which is the one I tried.) You need to have registered for the Insider Program for it to work, I think.
    • You get a choice of version, from a drop-down menu. Unless you have special circumstances, the top option ('Windows 10 Insider Preview - Build 14342') is probably the one to go for. Choose a language, too, and download the ISO file (should be 3.9 Gb or so).
    • Once downloaded, double click on the ISO file to mount it.
    • From the folder that appears, double click on 'setup.exe'.
    • Follow the prompts to install the preview build on your computer. (There will be warnings... be brave and accept them.) You will have the option to keep your files and settings – you'll probably want to do that. I found the install went much faster when I told it not to apply any updates as it went along, but your experience may be different.
    • After a series of restarts and logging in, you will eventually find yourself being introduced to a new version of Windows 10. Success!
    • Windows Update should now (hopefully) show you another update that can be installed. Mine showed an update to Build 14366, for instance. You'll probably want to do that – everything that I show you below worked better with the new update than it did before it...

2. Activate and install the bash terminal

The Ubuntu bash terminal, the thing we want to install, goes by the rather unsexy name of the 'Windows Subsytem for Linux (Beta)', WSL for short. You'll need to make an excursion into the deeper recesses of the Windows Settings and Control Panel in order to install it:
  • First, turn on Developer Mode. 
    • Click on Start, then Settings, then Update and Security, then For Developers.
    • On the screen that comes up, click on the radio button for 'Developer Mode'.
  • Next, install WSL.
    • In the Cortana 'Ask me anything' text box at the bottom of the screen, type 'features'.
    • From the menu that pops up, click on 'Turn Windows features on or off'.
    • Scroll down in the window that pops up, and click in the tick box for 'Windows Subsytem for Linux (Beta)'. Then select OK. The package should download and install, and you will be prompted to reboot. Do.
  • Next, run it for the first time.
    • Type 'bash' in the Cortana 'Ask me anything' box, and press return.
    • This will open a terminal window, which will ask you some simple questions. Yes, you do want to install it. It'll download more things, assuming you said 'y'.
    • At the end, it should ask you to set up your Linux username and password. Do so.
  • And then run it again!
    • Now you should find 'Bash on Ubuntu on Windows' in the start menu, or through the Cortana text box (try 'bash' again). And it should work. Huzzah!

3. Get X-Windows working

It's all very well to have the bash shell working. But the beauty of Linux, Unix and friends is that command line programs can open a wide variety of graphical outputs either from your own machine or on remote machines, through the X-Windows system. And so, until you have that functionality, it will only be a pale shadow of what is possible. Luckily, it isn't that hard to sort out.
  • Download and install the free VcXsrv X-Windows server application. (Internet people seem to think this is the best free option.)
  • Run VcXsrv. You should see an 'X' icon appear in your system tray.
  • Now set up bash to use your X-Windows server:
    • In your bash window type:  export DISPLAY=:0 (no misspellings, please)
  • You will need to install some apps that make X output to test it. Luckily bash comes with the Ubuntu/Debian package installer that does all the heavy lifting for you:
    • sudo apt-get install x11-apps  will install a set of simple apps that use the x11 system (you may need to enter your password to start the install)
    • xeyes  will generate a pair of graphical eyes that will follow your cursor around (sort of, it can be slow to update).
    • You could also try xcalc or  xclock (wonder what those do?)
  • To make the change permanent, you need to add the set-up information to your bash configuration file (.bashrc, in your home directory). If you don't know how to do that, try typing the following:
    • cd
    • nano .bashrc
    • scroll down to the bottom of the file
    • paste the  export command from above
    • ctrl–x to exit, 'y' to save changes.
  • You are now the proud owner of a (somewhat) functional Linux X-Windows system running natively on your Windows PC!

4. Things to try/figure out, and some observations

  • I successfully installed GMT5 under bash by following the standard GMT installation instructions for Ubuntu. (This did seem to need the extra, post-install Windows Update mentioned above, however.) I haven't yet tried all the commands, but plotting a simple pscoast world map worked just fine.
  • I also successfully installed gedit, the GNU text editor. It started out by crashing with every file save, but following the extra Windows Update (to build 14366) it seems much better behaved and less temperamental. I have been unable to change the configuration of the editor yet, though.
  • I had trouble getting ghostscript to run initially, but this too seems to have been sorted out with the update. ghostview worked from the off, on the other hand.
  • I have not yet located where the computer has situated the files involved on the windows file system. To be honest, I just haven't looked too hard yet.
  • I do know, however, that /mnt/c is the location of the C drive on my PC in the bash terminal.

2 comments:

  1. This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post. windows iso

    ReplyDelete
  2. When done, you will see a small Snipping Tool box. Click and drag the scissor-shaped icon (encircled red) to take the screenshot. https://screenshotapps.lighthouseapp.com/projects/143546/introduction

    ReplyDelete