Ubuntu Linux and Bash as a Windows Program!

An Ubuntu Bash shell as a Windows app? Fantastic! Here's how to proceed.

Microsoft has ruled the operating system world for many years, and it's staggering to see how many computers run Microsoft Windows in all its many variants. In May 2017, Microsoft announced it had an installed base of 1.4 billion. Sure, there also are much more than a billion devices now running Android, but if you're running a desktop or laptop computer, odds remain that it's running some version of Microsoft Windows.

Microsoft hasn't just ignored the rest of the OS world—although it sure took a long time for them to bail on Windows Mobile and accept Android—so it was with delight that I read that the next version of Windows 10 would include a simple app that lets you run a Linux shell.

No hassles with complex installations, no dual booting, no virtual machines you need to configure—just a simple app to find in the Microsoft Store and a program to click and run whenever you want to expand your knowledge of Bash or Linux.

Sort of.

At the time of this writing, the app requires that you're in the early release program (it's free to join, and you'll become a beta tester for the next version of Windows 10), but once you're signed up and running the early release version, it is indeed a download-and-go program.

By the time you read this article, however, what I'm running as an early release of Win10 should be the latest public update, so that roadblock will vanish.

To get started, you'll need to enable the Windows Subsystem for Linux (which also lets you run other flavors of Linux and is pretty cool), but start by searching in the Microsoft Store for "Ubuntu" to find Ubuntu Linux on Windows. The latest version of Ubuntu is supported in the app too: 16.04 LTS.

Click to launch it once installed, and you'll be confronted with a window like the one shown in Figure 1.

Figure 1. Ubuntu as a Windows App? Excellent!

It's interesting to note that some standard Linux commands return nothing—like who am i—but most of them work fine, and there even are dot files in my newly created home directory /home/taylor.

This is a Bash login shell. You can confirm your own shell a couple different ways, but I like this command: ps $$.

Are you curious about how the system identifies itself? uname -a is the standard Linux command to get the version, which reveals this interesting info:

$ uname -a
Linux VirtuaPC 4.4.0-43-Microsoft #1-Microsoft
 ↪Wed Dec 31 14:42:53 PST 2014
x86_64 x86_64 x86_64 GNU/Linux

VirtuaPC is indeed a virtual machine system (you can learn more about it at the Microsoft.com download center, if you're curious), and it's all part of the install, all hidden from us users. Thank goodness; VM installs can be tricky to configure properly.

What about Bash itself? It's easy to identify versions by using the --version flag:

$ bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Version 4.3.11 is reasonably current, although at the time of this writing the GNU archive shows the latest version is 4.4 (you can go here to see the latest).

Better yet, you're not quite in the late 1980s with the command line either, as the default TERM identifies itself to programs not as ANSI but as xterm-256color. This means you can have colors included in ls output, grep results and so on. Whether it looks nice and is legible is another story.

Let's give it a whirl—see Figure 2.

Figure 2. The Contents of /bin, in Glorious 256color

Changing the font size, window color scheme and so on is tricky because there's no UI to the Ubuntu program in Windows. It's also hard to get into the X Window System underlying the Ubuntu server that's running on your Windows system, so the standard trick of changing settings in .Xdefaults won't work.

Fortunately, you at least can improve the color scheme somewhat with the setterm command, then axe the default aliases to remove the clumsy ANSI colors. This command produces a far more readable terminal screen:

setterm -term linux -back white -fore black -clear

Ubuntu or Microsoft, someone has set it so that "white" is actually a very light grey, so the results are quite attractive. The problem is, run a command that knows how to output in color, and things get pretty broken pretty fast, as you can see in Figure 3 when I tried an ls -a.

Figure 3. New Color Scheme, Overwritten by LS

Open up the ~/.bashrc file, however, and you'll find that commands like ls have aliases that force the use of color. You also can check this with the alias command:

$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo
terminal || echo error)" "$(history|tail -n1|sed -e
 ↪egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

The solution is to go into the ~/.bashrc and comment out (preface each line with a # symbol) all of these aliases, and you'll be very close to Windows/Ubuntu configuration nirvana.

The only piece left that I kept hitting was the default ability of the vi editor (yeah, not emacs) to use color. Open up a file like my .profile, and it's out-of-control color soup and completely unreadable, as you can see in Figure 4.

Figure 4. Vi's color scheme is ghastly!

Again, it's fixable. This time, you want to create a new file in your home directory called .vimrc that contains this single line:

syntax off

Confusingly, syntax is the parsing and display of different file elements in different colors. Can't read the screen to create this file? In vi type this:

:syntax off

and it'll turn off all that crazy color stuff.

Those few tweaks will get you much farther toward being able to use and easily read the Ubuntu window in Windows until there's an actual settings or preferences option that becomes available.

Give it a try, and if you find out how to make the typeface bigger or any other useful configuration tweaks, let me know in the comments below, and I'll revisit this later with the best user submissions.

Dave Taylor has been hacking shell scripts on UNIX and Linux systems for a really long time. He's the author of Learning Unix for Mac OS X and Wicked Cool Shell Scripts. You can find him on Twitter as @DaveTaylor, and you can reach him through his tech Q&A site: Ask Dave Taylor.

Load Disqus comments