Starter guide on Bash on Windows: How to get it running, installing apps and a shell, and customization

by Simone Franco6 months ago

Good day, and welcome to this guide!

Here we will try to explain and cover most of the Bash on Windows features that are included with Windows 10, how we can use them, and how can we set it up to achieve a great part of Linux functionalities on our Windows PCs.

The first part of this guide will show how to install Bash on Windows, that is the most essential part, needed to make it run. Then we’ll install some Linux programs, to see how they work, and we’ll expand the features of our subsystem to achieve more, for example adding a shell, and see how Windows and Linux can co-operate. This guide was written using Windows 10 Insider Preview, build 15055, so any build in the Redstone 2 range, or the final Creators Update and later, should work. You might also try this on Anniversary update, but keep in mind that it might have some differences, as Microsoft expanded the subsystem capabilities in RS2.

Let’s get started!


Installing the Linux Subsystem

 

To install the Linux Subsystem, we need to go into the old Control Panel, into the section to enable/disable Windows Features. Here we’ll find “Windows Subsystem for Linux (Beta)”. Let’s enable it, confirm, and you will be probably asked to reboot, after it finishes.

Next, we’ll have to download the system files needed to make it run: open the Command Prompt, and type:

bash

You’ll need to type this each time you will want to run the bash command line. You’ll be greeted with a welcome message, read it and follow the setup. While it is downloading, let’s talk about it.

The Linux subsystem is basically the Ubuntu userspace (no Linux kernel) running on Windows. A “real” Ubuntu distribution includes a standard set of programs (or “packages”) preinstalled, and a GUI called Unity that allows the user to see an interface instead of a bash command line. Windows Subsystem on Linux installs a special version called Ubuntu Cloud, which comes without any graphical features. This means we’ll just get the Bash Shell to interact with our Linux subsystem… for now. Once the installation is done, we’ll be asked for a UNIX username and a password. Choose your password carefully, because the only way, if you lose it, will be to uninstall Bash and reinstall it. Once done, you’ll be in Bash on Windows:


The Basics

 

Now that we have a Linux subsystem running, what can we do with it? Let’s see some basic commands for the bash.

ls

lists the files and folders in your currently navigated folder. To navigate folders, type:

cd [path]

If you choose no path, you’ll be brought to your home directory. If you specify a path to a folder it will navigate to that. In case you want to go one level up, cd .. is your friend.

So, why don’t we start installing some basic packages? A developer might need “gcc” to compile C, C++, Objective-C and more kinds of code, and it doesn’t come with our Ubuntu image.

On Ubuntu, the package manager is called Advanced Packaging Tool, short APT.

First, let’s update the package informations, so our APT will know where to search and download the package we want to install.
In this demonstration we’re going to be installing gcc.

Just like on Windows, a regular user doesn’t get permission to do everything, which is why we need to use a little tool called sudo. It will prompt to enter the password of the current user and then execute the operation you specified as root. The root user has permission to do pretty much everything on a system.

sudo apt-get update

After the package information has updated, we can proceed to installing a package. To do so, we type:

sudo apt-get install [Package Name]

In our case:

sudo apt-get install gcc

This is what we’ll get, confirm it so it can install:

And that’s it, the gcc package is now installed.

If you are not a developer, this might not be very useful for you. Right now you could open a text editor named “nano”, but this might still sound boring:

nano

and the nano “interface” will show up.

To exit, press Ctrl+X.

Linux has a ton of other commands, and this was just the base to start. There’s still 99.9% of Bash left to learn. These were the basic things that Bash on Windows lets you do. You could stop reading now, if this is enough for you. If you want things to get more interesting, we’ve got you covered, keep reading!


Running windowed applications

 

Bash on Windows can’t run graphical software that requires a shell and a window manager out of the box, but we can get around that.
To solve this problem, we can use a program like Xming, that will act as window manager and screen for linux. Using this, we will be able Linux windowed apps like if they were Windows apps!
Once it installs, run it, and let’s start working already.
We’re going to start with something basic: SciTE is a simple and basic text editor, with support for code markup for developers, with a very basic UI.
To install it, let’s run this from bash:
sudo apt-get install scite
and confirm it. This will take a while, depending mostly on your internet connection speed. If you have a potato connection like me, this will take 10-15 minutes. To run a program on a window using xming, we type:
DISPLAY=:0 programName
so again, once it gets installed, in our case:
DISPLAY=:0 scite
If you did everything correcly, this will show up in a separate window:
Well done! Your program is now running. You won’t be able to use the bash commands while the program is running. To do so, run the command with ” &” at the end to launch a seperate process.
We can try running other programs (you’ll need to install them), even if they are available on Windows too, like GIMP, a free advanced image editor, very powerful, Firefox, the notorious web browser, or a more advanced programming tool, like Sublime Text.
There are a lot of smaller Linux programs that are more specific to do some tasks better than Windows can, and you’ll be most likely able to run them like we did with SciTE.
But now let’s move on, and make things a bit easier.
Suppose you want to run SciTE without opening xming, going to the bash and typing the command. The very first thing to do, is to put xming to start when Windows boots. If your computer is not performing really well, it will probably be better to not do this. Next step: we’re going to create a desktop shortcut for our program.
Create a new shortcut and put as location (quote marks included):
C:\Windows\System32\bash.exe -c “DISPLAY=:0 scite”
Save the shortcut, and try to run it.
Shall we go a step further? I did, and I must tell you the best part has yet to come.

Installing a shell, and ditching the bash line

 

(Note: This time for real. If your computer is not performing well, skip this. This step will make things a lot easier, but will probably slow a bit (or a lot) your computer if your hardware is not capable of running it.)
It’s time to ditch the command line! On a normal Linux distribution, like we said before, shells hide the Bash line and give the user a more good looking interface. Let’s get one installed!
We’re not going to use gnome, one of the most famous and user-friendly shells out there, since it won’t work here. We’re going to use xfce, a simple and light one, to start.
We start installing it, like any other application:
sudo apt-get install xfce4
once done, run it with:
DISPLAY=:0 startxfce4
Let it start, and you should be welcomed with this message, if it installed correctly. If something didn’t work, try installing xfce again.
Select “Use default config”, unless you already know how xfce works. The shell will start and this is how it shows for the first time:
Play with it a bit, edit the bars that appear, and you’ll be able to end up with something a bit better like this:
Nice! Now you’ll be able to run programs from the xfce shell. Try running SciTE, or the integrated file manager, from the Applications Menu.
You could install some more things, like a terminal with tabs support: open a terminal from the Applications Menu on xfce4, and run:
sudo apt-get install xfce4-terminal
And so on. You can now personalize it the way you want!
Personally, I have set up my pc so at boot, it starts xming and the xfce shell so I always have both Windows and Linux apps at the same time. To run xfce at start, make a shortcut like we did with SciTE, with the following location (quote marks included):
C:\Windows\System32\bash.exe -c “DISPLAY=:0 startxfce4”
Put the shortcut in Windows’s Automatic Run, togheter with xming.
Another thing that I do frequently is use Linux apps to work on my files on Windows. In fact, the entire partition where Windows is installed is mounted on Linux: you can find it by going into the root of the linux file manager, and entering /mnt/c/
And that’s a wrap! This is just how I have configured my Linux Subsystem. You might come up with a even better solution, or have some better file explorers for the shell, or also an entire better shell! If you want to share your discoveries, use the comments below here. I’ll edit the post to include your tips!
Comments