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
- 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
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
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
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
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 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 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.
Note: In the steps below, we will 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 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
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.