Post

How to run graphical Linux applications on Windows 10 using the Windows Subsystem for Linux (WSL) 1.0

A step-by-step guide on installing Bash on Ubuntu on Windows, with additional steps for running graphical Linux applications.

How to run graphical Linux applications on Windows 10 using the Windows Subsystem for Linux (WSL) 1.0

Note : This is an old guide that only applies to WSL 1.0. WSL 2.0 supports GUI applications out-of-the-box.

The Windows Subsystem for Linux (WSL) was introduced by Microsoft in the Windows 10 Anniversary Update. It allows users to run a full Linux user space in Windows. It is a much nicer approach for most applications than Cygwin, or using a Linux VM. It is not an emulator either. Think of it as GNU/Linux/Windows (apologies to Richard Stallman). This guide starts off with Microsoft’s instructions for installing the WSL, and then goes a few steps further by describing how to run graphical Linux applications.

Prerequisites

Your PC must be running (at a minimum) a 64-bit version of Windows 10 with the Anniversary Update. The Creator’s Update is recommended.

To find your PC’s CPU architecture and Windows version/build number, open Settings>System>About. Look for the System Type and Version fields respectively, as shown in the screenshot below.

A screenshot of the About section of the Windows 10 Settings app

If your build is below 14393, try checking for updates.

Enable the Windows Subsystem for Linux feature

You can enable the feature using a GUI or command-line interface.

GUI Method

  1. From the Start Menu, search for “Turn Windows features on or off” (type ‘turn’)
  2. Select Windows Subsystem for Linux
    The Windows features dialog box in Windows 10

  3. Click OK

Command-line Method

Open a PowerShell prompt as administrator and run:

1
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

After enabling Windows Subsystem for Linux

Restart your computer when prompted.

It is important that you DO restart when prompted as some of the infrastructure which the Windows Subsystem for Linux requires can only be loaded during Windows’ boot-up sequence.

Install your Linux distribution of choice

Linux distributions can be installed using a script, or by using the Microsoft Store links below:

After installation your Linux distribution will be located at: %localappdata%\lxss\ This directory is marked as a hidden system folder for a very good reason:

Avoid creating and/or modifying files in this location using Windows tools and apps! If you do, it is likely that your Linux files will be corrupted and data loss may occur. Please read this blog post for more information.

Create a UNIX user

The first time you launch a Linux distribution in Windows, you will be prompted to create a UNIX username and password.

A screenshot of a new UNIX user being created for Bash on Ubuntu on Windows

This UNIX username and password has no relationship to your Windows username and password, and it can be different.**

Use the same username that you use on remote Linux/UNIX systems, so you won’t need to specify it in individual configuration files, or every time you run commands like ssh. Read more.

Update the Linux distribution

After you have set up your user, update the OS.

To do this on Debian/Ubuntu based distributions, run:

1
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y

Install common tools

The Debian distribution for WSL is minimal, so many packages that you might expect to be installed, such as ca-certificates, are not installed. To fix this, run:

1
2
sudo apt install -y ca-certificates findutils command-not-found vim nano curl
openssh-client less screen apt-utils top htop whois git python3-pip

Accessing the Windows filesystem from WSL

Windows drives are mounted by their drive letters under /mnt. For example, your Windows C: drive is accessible via /mnt/c.

To make it easier to access your Windows user directory, consider adding a symbolic link, such as:

1
ln -s /mnt/c/Users/Sean/ ~/winhome

On Amazon WorkSpaces, this your Windows user directory is located in /mnt/d/Users.

That way, your Windows user directory is accessible from ~/winhome.

Graphical Applications

In order to run Linux GUI applications using WSL, you must:

  1. Install a X server for Windows
  2. Configure bash to tell GUIs to use the local X server

Install VcXsrv

In order to run graphical Linux applications, you’ll need an X server.

VcXsrv is the only fully open source and up-do-date native X server for Windows. Download and run the latest installer, then locate the XLaunch shortcut in the Start Menu, and click it.

You will be greeted with a setup wizard. Accept the default options. On the last page of the wizard, click on the Save configuration button, and save the configuration file in %appdata%\Microsoft\Windows\Start Menu\Programs\Startup, so vcXsrv will launch at startup without asking about these options, then click on the Finish button.

You may receive a prompt to allow it through your firewall. Cancel/deny this request! Otherwise, other computers on your network could access the server.

A X icon will appear in your system tray.

Configure bash to use the local X server

  1. In bash run:
    echo "export DISPLAY=localhost:0.0" >> ~/.bashrc

  2. To have the configuration changes take effect, restart bash, or run:
    . ~/.bashrc

Instructions for fish shell users

If you use fish instead of bash:

  1. echo "set -x DISPLAY localhost:0.0" >> ~/.config/fish/config.fish
  2. To have the configuration changes take effect, restart fish, or run:
    . ~/.config/fish/config.fish

Test a graphical application

  1. Install x11-apps
    sudo apt-get install x11-apps

  2. Run xeyes

A new window will open, containing a pair of eyes that will follow your mouse movements.

Running remote GUI applications over SSH

To use a GUI application from a server, simply use the -X switch with the ssh command, for example:

And run the GUI application from the shell prompt.

Using Visual Studio Code

Instead on installing the Linux version on Visual Studio Code on your WSL Linux distribution, install Visual Studio Code in Windows, and add the Remote Development extension pack.

After reloading Visual Studio Code, click on the green arrows at the bottom right corner of the window, and select Remote-WSL: New window action.

A new window will open with a Linux shell and editor. You will be able to edit files on the Linux file system.

Any Visual Studio Code extensions need to be installed in your Windows instance of Visual Studio Code first, and then on the WSL instance.

Recommended extensions for information security professionals include:

References

This post is licensed under CC BY 4.0 by the author.