Jesse Laprade

Setting up graphical applications in Windows Subsystem for Linux

2019-12-03

This guide teaches you how to access graphical applications from Microsoft’s Windows Subsystem for Linux. This guide is intended for people who are familiar with editing files using command line tools.

This guide consists of the following sections:

Conventions used in this guide

Requirements

Note: If you have Windows 10 or above, but have not installed Windows Subsystem for Linux or a Linux distribution for Windows Subsystem for Linux, Microsoft’s website provides instructions on how to do this.

Preparing Windows Subsystem for Linux

The preparations in this section prevents settings and file permissions from resetting when you close a terminal window, create a place for graphical applications to run, and prepare your command line configuration files for handling calls to graphical applications.

To prepare Windows Subsystem for Linux

  1. Allow Linux and Microsoft Windows to retain separate file permissions when using chmod in Windows Subsystem for Linux by adding the following contents to /etc/wsl.conf:

    [automount]
    options = "metadata"
  2. Download Xming here

  3. Install Xming

  4. Add the following contents to .bashrc:

    export DISPLAY=:0
  5. Install the graphical packages you want to use by running the following command:

    sudo apt install

    Note: In Step 1 above, ensure you are editing /etc/wsl.conf with root permissions using sudo or su.

    Example: In Step 5 above, to install the xfce4-terminal package, you would run the following command:

    sudo apt install xfce4-terminal

Enabling Xming on startup

The instructions in this section teach you how to enable Xming every time Microsoft Windows starts. This removes the need to manually start the Xming application every time you start your computer.

To enable Xming on startup

  1. Navigate to the following directory in Microsoft Windows:

    C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
  2. Right-click on an empty space

  3. Click New > Shortcut

  4. Under Type the location of the item:, enter the following value:

    "C:\Program Files (x86)\Xming\Xming.exe"
  5. Click Next

  6. Right-click the new shortcut

  7. Beside Target:, enter the following value:

    "C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow
  8. Ensure the value beside Start in: is the following value:

    "C:\Program Files (x86)\Xming"

Note 1: In Step 1 above, you need to replace USERNAME with your Microsoft Windows username.

Example: My Microsoft Windows username is Jesse, so I would change the line:

C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

to

C:\Users\Jesse\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Note 2: In Steps 4 and 8 above, you may have to alter the path to Xming, depending on where you installed it.

Creating a Windows desktop shortcut to a Windows Subsystem for Linux graphical application

The instructions in this section teach you how to create a Microsoft Windows desktop shortcut. Shortcuts to graphical applications remove the need to open a terminal emulator every time you want to open a graphical application.

Note: In the steps below, we use the xfce4-terminal application as an example.

To create a Windows desktop shortcut to a Windows Subsystem for Linux graphical application

  1. Right-click the desktop

  2. Click New… > Shortcut

  3. Under Type the location of the item, enter the following value:

    powershell -windowstyle hidden -Command "iex "bash ~ -c 'DISPLAY=:0 xfce4-terminal'" "

This section guides you through creating command line shortcuts called symlinks. This allows you to access Microsoft Windows files and directories without having to type /mnt/c/Users/USERNAME/ before every Microsoft Windows path.

To navigate to your Microsoft Windows home directory for Windows Subsystem for Linux

  1. Navigate to the directory in which you want the symlink to exist using cd /path/to/a/directory

  2. Run the following command:

    ln -s /mnt/c/Users/USERNAME/PATH/TO/DIRECTORY/ ~/path/to/your/shortcut

Example: If a user with the Microsoft Windows username “Sarah” wanted to create a symlink from Windows Subsystem for Linux to Sarah’s Documents directory in Microsoft Windows, they would run:

ln -s /mnt/c/Users/Sarah/Documents/ ~/doc

In this example, Sarah can now access their Microsoft Windows Documents directory by typing cd doc from their Windows Subsystem for Linux home directory, instead of typing out cd /mnt/c/Users/Sarah/Documents every time.