Setting up graphical applications in Windows Subsystem for Linux

2019-12-03 00:00

This guide will teach 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

Preparing Windows Subsystem for Linux

The preparations in this section will prevent 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

Enabling Xming on startup

The instructions in this section will help you enable Xming everytime Microsoft Windows starts. This will remove the need to manually start the Xming application everytime 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"

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

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

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 will guide you through creating command line shortcuts called symlinks. This will help you 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

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.