git.m455.casa

m455.casa

clone url: git://git.m455.casa/m455.casa


html/archive/2019/setting-up-graphical-applications-in-windows-subsystem-for-linux.html

1 <!DOCTYPE html>
2 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
3 <head>
4 <meta charset="utf-8" />
5 <meta name="generator" content="pandoc" />
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
7 <title>Setting up graphical applications in Windows Subsystem for Linux</title>
8 <style>
9 code{white-space: pre-wrap;}
10 span.smallcaps{font-variant: small-caps;}
11 span.underline{text-decoration: underline;}
12 div.column{display: inline-block; vertical-align: top; width: 50%;}
13 div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14 ul.task-list{list-style: none;}
15 </style>
16 <style>
17 body {
18 line-height: 1.5;
19 font-family: sans-serif;
20 font-size: 18px;
21 margin: 20px auto;
22 max-width: 630px;
23 }
24
25 a {
26 color: blue;
27 }
28
29 code, pre {
30 background-color: #fddee3;
31 font-size: 14px;
32 }
33
34 pre {
35 padding: 25px 25px;
36 overflow: auto;
37 }
38
39 pre code {
40 white-space: pre;
41 }
42
43 img {
44 max-width: 100%;
45 }
46
47 table {
48 border-collapse: collapse;
49 }
50
51 table caption {
52 font-weight: bold;
53 margin: 10px 0px;
54 text-align: left;
55 }
56
57 th, td {
58 border: 1px solid #000;
59 padding: 4px;
60 }
61
62 blockquote {
63 border-left: 3px solid #000;
64 padding-left: 10px;
65 }
66
67 .border {
68 border: 1px solid #000;
69 margin: 25px 0px;
70 padding: 5px 25px;
71 }
72
73 @media only screen and (max-width: 700px) {
74 body {
75 margin: 10px;
76 }
77 }
78
79 @media (prefers-color-scheme: dark) {
80 body {
81 background-color: #111;
82 color: #eee;
83 }
84 a {
85 color: #009fff;
86 }
87 code, pre {
88 background-color: #111;
89 color: #fd6363;
90 }
91 pre {
92 padding: 15px 25px;
93 }
94 blockquote {
95 border-left: 3px solid #666;
96 }
97 .border, th, td {
98 border: 1px solid #666;
99 }
100 }
101 </style>
102 </head>
103 <body>
104 <main>
105 <h2 id="setting-up-graphical-applications-in-windows-subsystem-for-linux">Setting up graphical applications in Windows Subsystem for Linux</h2>
106 <p>2019-12-03 00:00</p>
107 <p>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.</p>
108 <p>This guide consists of the following sections:</p>
109 <ul>
110 <li><a href="#conventions-used-in-this-guide">Conventions used in this guide</a></li>
111 <li><a href="#requirements">Requirements</a></li>
112 <li><a href="#preparing-windows-subsystem-for-linux">Preparing Windows Subsystem for Linux</a></li>
113 <li><a href="#enabling-xming-on-startup">Enabling Xming on startup</a></li>
114 <li><a href="#creating-a-windows-desktop-shortcut-to-a-windows-subsystem-for-linux-graphical-application">Creating a Windows desktop shortcut to a Windows Subsystem for Linux graphical application</a></li>
115 <li><a href="#navigating-to-your-windows-home-directory-from-windows-subsystem-for-linux">Navigating to your Windows home directory from Windows Subsystem for Linux</a></li>
116 </ul>
117 <h3 id="conventions-used-in-this-guide">Conventions used in this guide</h3>
118 <ul>
119 <li><strong>Note</strong>: Signifies additional information</li>
120 <li><strong>Tip</strong>: Signifies an alternative procedure for completing a step</li>
121 <li><strong>Warning</strong>: Signifies that damage, such as data loss, may occur</li>
122 <li><strong>Example</strong>: Shows how a procedure would be performed in a real scenario</li>
123 <li><code>Inline code and code blocks</code>: Signify package names, filenames, file contents, or commands</li>
124 <li><code>&lt;variable&gt;</code> Signifies that the text between the <code>&lt;</code> and <code>&gt;</code> should be replaced, and the <code>&lt;</code> and <code>&gt;</code> should be removed</li>
125 <li><strong>Bold font</strong> Signifies user interface items</li>
126 </ul>
127 <h3 id="requirements">Requirements</h3>
128 <ul>
129 <li>Windows 10 or above</li>
130 <li>Windows Subsystem for Linux</li>
131 <li>A Linux distribution to use on Windows Subsystem for Linux</li>
132 </ul>
133 <aside class="border">
134 <p>
135 <strong>Note</strong>: If you have Windows 10 or above, but have not installed Windows Subsystem for Linux or a Linux distribution for Windows Subsystem for Linux, <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">Microsoft’s website</a> provides instructions on how to do this.
136 </p>
137 </aside>
138 <h3 id="preparing-windows-subsystem-for-linux">Preparing Windows Subsystem for Linux</h3>
139 <p>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.</p>
140 <h4 id="to-prepare-windows-subsystem-for-linux">To prepare Windows Subsystem for Linux</h4>
141 <ol type="1">
142 <li><p>Allow Linux and Microsoft Windows to retain separate file permissions when using <code>chmod</code> in Windows Subsystem for Linux by adding the following contents to <code>/etc/wsl.conf</code>:</p>
143 <pre><code> [automount]
144 options = &quot;metadata&quot;</code></pre></li>
145 <li><p>Download Xming <a href="https://sourceforge.net/projects/xming/">here</a></p></li>
146 <li><p>Install Xming</p></li>
147 <li><p>Add the following contents to <code>.bashrc</code>:</p>
148 <pre><code> export DISPLAY=:0</code></pre></li>
149 <li><p>Install the graphical packages you want to use by running the following command:</p>
150 <pre><code> sudo apt install</code></pre></li>
151 </ol>
152 <aside class="border">
153 <p>
154 <strong>Note</strong>: In Step 1 above, ensure you are editing <code>/etc/wsl.conf</code> with root permissions using <code>sudo</code> or <code>su</code>.
155 </p>
156 </aside>
157 <aside class="border">
158 <p>
159 <strong>Example</strong>: In Step 5 above, to install the <code>xfce4-terminal</code> package, you would run the following command:
160 </p>
161 <pre>
162 sudo apt install xfce4-terminal
163 </pre>
164 </aside>
165 <h3 id="enabling-xming-on-startup">Enabling Xming on startup</h3>
166 <p>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.</p>
167 <h4 id="to-enable-xming-on-startup">To enable Xming on startup</h4>
168 <ol type="1">
169 <li><p>Navigate to the following directory in Microsoft Windows:</p>
170 <pre><code> C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup</code></pre></li>
171 <li><p>Right-click on an empty space</p></li>
172 <li><p>Click <strong>New</strong> &gt; <strong>Shortcut</strong></p></li>
173 <li><p>Under <strong>Type the location of the item:</strong>, enter the following value:</p>
174 <pre><code> &quot;C:\Program Files (x86)\Xming\Xming.exe&quot;</code></pre></li>
175 <li><p>Click <strong>Next</strong></p></li>
176 <li><p>Right-click the new shortcut</p></li>
177 <li><p>Beside <strong>Target:</strong>, enter the following value:</p>
178 <pre><code> &quot;C:\Program Files (x86)\Xming\Xming.exe&quot; :0 -clipboard -multiwindow</code></pre></li>
179 <li><p>Ensure the value beside <strong>Start in:</strong> is the following value:</p>
180 <pre><code> &quot;C:\Program Files (x86)\Xming&quot;</code></pre></li>
181 </ol>
182 <aside class="border">
183 <p>
184 <strong>Note 1</strong>: In Step 1 above, you will have to replace <code>USERNAME</code> with your Microsoft Windows username.
185 </p>
186 <aside class="border">
187 <p>
188 <strong>Example</strong>: My Microsoft Windows username is Jesse, so I would change the line:
189 </p>
190 <pre>
191 C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
192 </pre>
193 <p>
194 to
195 </p>
196 <pre>
197 C:\Users\Jesse\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
198 </pre>
199 </aside>
200 </aside>
201 <aside class="border">
202 <p>
203 <strong>Note 2</strong>: In Steps 4 and 8 above, you may have to alter the path to Xming, depending on where you installed it.
204 </p>
205 </aside>
206 <h3 id="creating-a-windows-desktop-shortcut-to-a-windows-subsystem-for-linux-graphical-application">Creating a Windows desktop shortcut to a Windows Subsystem for Linux graphical application</h3>
207 <p>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.</p>
208 <aside class="border">
209 <p>
210 <strong>Note</strong>: In the steps below, we will use the <code>xfce4-terminal</code> application as an example.
211 </p>
212 </aside>
213 <h4 id="to-create-a-windows-desktop-shortcut-to-a-windows-subsystem-for-linux-graphical-application">To create a Windows desktop shortcut to a Windows Subsystem for Linux graphical application</h4>
214 <ol type="1">
215 <li><p>Right-click the desktop</p></li>
216 <li><p>Click <strong>New… &gt; Shortcut</strong></p></li>
217 <li><p>Under <strong>Type the location of the item</strong>, enter the following value:</p>
218 <pre><code> powershell -windowstyle hidden -Command &quot;iex &quot;bash ~ -c &#39;DISPLAY=:0 xfce4-terminal&#39;&quot; &quot;</code></pre></li>
219 </ol>
220 <h3 id="navigating-to-your-windows-home-directory-from-windows-subsystem-for-linux">Navigating to your Windows home directory from Windows Subsystem for Linux</h3>
221 <p>This section will guide you through creating command line shortcuts called <a href="https://en.wikipedia.org/wiki/Symbolic_link">symlinks</a>. This will help you access Microsoft Windows files and directories without having to type <code>/mnt/c/Users/USERNAME/</code> before every Microsoft Windows path.</p>
222 <h4 id="to-navigate-to-your-microsoft-windows-home-directory-for-windows-subsystem-for-linux">To navigate to your Microsoft Windows home directory for Windows Subsystem for Linux</h4>
223 <ol type="1">
224 <li><p>Navigate to the directory in which you want the symlink to exist using <code>cd /path/to/a/directory</code></p></li>
225 <li><p>Run the following command:</p>
226 <pre><code> ln -s /mnt/c/Users/USERNAME/PATH/TO/DIRECTORY/ ~/path/to/your/shortcut</code></pre></li>
227 </ol>
228 <aside class="border">
229 <p>
230 <strong>Example</strong>: 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:
231 </p>
232 <pre>
233 ln -s /mnt/c/Users/Sarah/Documents/ ~/doc
234 </pre>
235 </aside>
236 <p>In this example, Sarah can now access their Microsoft Windows Documents directory by typing <code>cd doc</code> from their Windows Subsystem for Linux home directory, instead of typing out <code>cd /mnt/c/Users/Sarah/Documents</code> every time.</p>
237 </main>
238 </body>
239 </html>