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
- Preparing Windows Subsystem for Linux
- Enabling Xming on startup
- Creating a Windows desktop shortcut to a Windows Subsystem for Linux graphical application
- Navigating to your Windows home directory from Windows Subsystem for Linux
Conventions used in this guide
- Note: Signifies additional information
- Tip: Signifies an alternative procedure for completing a step
- Warning: Signifies that damage, such as data loss, may occur
- Example: Shows how a procedure would be performed in a real scenario
Inline code and code blocks
: Signify package names, filenames, file contents, or commands<variable>
Signifies that the text between the<
and>
should be replaced, and the<
and>
should be removed- Bold font Signifies user interface items
Requirements
- Windows 10 or above
- Windows Subsystem for Linux
- A Linux distribution to use on Windows Subsystem for Linux
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
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"
Download Xming here
Install Xming
Add the following contents to
.bashrc
:export DISPLAY=:0
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 usingsudo
orsu
.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
Navigate to the following directory in Microsoft Windows:
C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Right-click on an empty space
Click New > Shortcut
Under Type the location of the item:, enter the following value:
"C:\Program Files (x86)\Xming\Xming.exe"
Click Next
Right-click the new shortcut
Beside Target:, enter the following value:
"C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow
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
Right-click the desktop
Click New… > Shortcut
Under Type the location of the item, enter the following value:
powershell -windowstyle hidden -Command "iex "bash ~ -c 'DISPLAY=:0 xfce4-terminal'" "
Navigating to your Windows home directory from Windows Subsystem for Linux
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
Navigate to the directory in which you want the symlink to exist using
cd /path/to/a/directory
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.