<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Xucong ZHAN</title>
    <description>The latest articles on DEV Community by Xucong ZHAN (@hymanzhan).</description>
    <link>https://dev.to/hymanzhan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F117526%2Fe0cdb525-458e-4e81-b2ea-9569c92756c6.png</url>
      <title>DEV Community: Xucong ZHAN</title>
      <link>https://dev.to/hymanzhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hymanzhan"/>
    <language>en</language>
    <item>
      <title>Setting up WSL 2 for Web Development</title>
      <dc:creator>Xucong ZHAN</dc:creator>
      <pubDate>Sat, 04 Apr 2020 01:15:14 +0000</pubDate>
      <link>https://dev.to/hymanzhan/setting-up-wsl-2-for-web-development-3202</link>
      <guid>https://dev.to/hymanzhan/setting-up-wsl-2-for-web-development-3202</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This post was originally posted on my personal blog: &lt;a href="https://xzhan.me/2020/04/configuring-wsl-2/" rel="noopener noreferrer"&gt;xzhan.me&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Recently, WSL 2 landed on the slow ring of Windows Preview. As a fan of WSL myself, I am eager to try it out and enjoy the improved I/O performance it brings to the table. So without further delay, I opted in and upgraded to Win10 2004 and enabled WSL 2. HOWEVER (there is always a "however"), not all things are smoothed out yet at the time of writing. In this post, I am going to write about my experience of setting up WSL 2 for a Django web development workflow.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Zsh

&lt;ul&gt;
&lt;li&gt;WSL 2 I/O Performance Catch&lt;/li&gt;
&lt;li&gt;Exclude Windows PATH&lt;/li&gt;
&lt;li&gt;Zsh History Search &amp;amp; Starship&lt;/li&gt;
&lt;li&gt;Typeface &amp;amp; Nerd Font&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Python &amp;amp; Node&lt;/li&gt;

&lt;li&gt;

Web &amp;amp; Database

&lt;ul&gt;
&lt;li&gt;Install database in WSL&lt;/li&gt;
&lt;li&gt;Accessing database Running on Windows from WSL&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;VS Code&lt;/li&gt;

&lt;li&gt;Summary&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Zsh
&lt;/h2&gt;

&lt;p&gt;My &lt;code&gt;.zshrc&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# enabling some built-in features&lt;/span&gt;
zstyle &lt;span class="s1"&gt;':completion:*'&lt;/span&gt; menu &lt;span class="k"&gt;select
&lt;/span&gt;autoload &lt;span class="nt"&gt;-U&lt;/span&gt; compinit &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; compinit
&lt;span class="nv"&gt;HISTFILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;~/.zsh_history
&lt;span class="nv"&gt;HISTSIZE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10000
&lt;span class="nv"&gt;SAVEHIST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1000
setopt SHARE_HISTORY

&lt;span class="c"&gt;# personal aliases&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;mooc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd /home/xzhan/Development/MOOC"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;proj&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd /home/xzhan/Development/Projects"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;pk&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd /home/xzhan/Development/Packages"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;wk&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"cd /home/xzhan/Development/Work"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;da&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"deactivate"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;dcu&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"docker-compose up"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;dcud&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"docker-compose up -d"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;dex&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"docker-compose exec"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;dcd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"docker-compose down"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;dcs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"docker-compose stop"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;dcl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"docker-compose logs"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;vim&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"nvim"&lt;/span&gt;
&lt;span class="nb"&gt;alias ls&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"lsd"&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;ll&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"lsd -l"&lt;/span&gt;

&lt;span class="c"&gt;# added for vscode&lt;/span&gt;
&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/mnt/c/Users/zhanx/AppData/Local/Programs/'Microsoft VS Code'/bin/code"&lt;/span&gt;

&lt;span class="c"&gt;# added for miniconda3&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/xzhan/miniconda3/bin:&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# added for pipenv&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PIPENV_VENV_IN_PROJECT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;True
&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;pipenv &lt;span class="nt"&gt;--completion&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# added for rust&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/xzhan/.cargo/bin:&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# added for homebrew&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/linuxbrew/.linuxbrew/bin:&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="c"&gt;# added for nvm&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;NVM_DIR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-z&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;XDG_CONFIG_HOME&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;printf&lt;/span&gt; %s &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/.nvm"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;printf&lt;/span&gt; %s &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;XDG_CONFIG_HOME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/nvm"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVM_DIR&lt;/span&gt;&lt;span class="s2"&gt;/nvm.sh"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$NVM_DIR&lt;/span&gt;&lt;span class="s2"&gt;/nvm.sh"&lt;/span&gt;

&lt;span class="c"&gt;# added for zsh-history-substring-search&lt;/span&gt;
&lt;span class="nb"&gt;source&lt;/span&gt; /home/linuxbrew/.linuxbrew/share/zsh-history-substring-search/zsh-history-substring-search.zsh
bindkey &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$terminfo&lt;/span&gt;&lt;span class="s2"&gt;[kcuu1]"&lt;/span&gt; history-substring-search-up
bindkey &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$terminfo&lt;/span&gt;&lt;span class="s2"&gt;[kcud1]"&lt;/span&gt; history-substring-search-down

&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;starship init zsh&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;A few things to pay attention to here:&lt;/p&gt;

&lt;h3&gt;
  
  
  WSL 2 I/O Performance Catch
&lt;/h3&gt;

&lt;p&gt;WSL 2 has a much improved I/O performance, but only on the Linux partition. As described in &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/wsl2-ux-changes#cross-os-file-speed-will-be-slower-in-initial-preview-builds" rel="noopener noreferrer"&gt;this documentation&lt;/a&gt; WSL 2 has a much slower performance when performing cross-OS I/O tasks. Outcome include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Unacceptable slow performance with zsh shell prompt/plugins&lt;/strong&gt;, like &lt;a href="https://ohmyz.sh/" rel="noopener noreferrer"&gt;oh-my-zsh&lt;/a&gt; or &lt;a href="https://starship.rs/" rel="noopener noreferrer"&gt;starship&lt;/a&gt;. I don't know enough about the internal implementation of these projects to identify the direct reason, but the outcome is printing a new line takes over 30s 🙃:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1e57fvq1a248srks3i16.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1e57fvq1a248srks3i16.gif" alt="Slow ZSH with starship"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Slow startup performance.&lt;/strong&gt; Sometimes the WSL prompt can take over 15s to start. One way to mitigate this is to exclude the inclusion of Windows PATH, with which I can reduce the startup time down to 1s. This will be elaborated in the next point.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are interested you can follow up on the progress at &lt;a href="https://github.com/microsoft/WSL/issues/4197" rel="noopener noreferrer"&gt;this Github issue&lt;/a&gt;. Note that the problem is clearly known and actively being worked on so hold yourself from spam the thread with +1 comments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exclude Windows PATH
&lt;/h3&gt;

&lt;p&gt;As mentioned, excluding Windows PATH can bring some nice performance boost. If you are not relying on Windows programs anyways, you can safely exclude it by adding this to &lt;code&gt;/etc/wsl.conf&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;

&lt;span class="nn"&gt;[Interop]&lt;/span&gt;
&lt;span class="py"&gt;appendWindowsPath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="err"&gt;False&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;"But what about VS Code?! 😱" Don't worry my friend. I have you covered. Notice that we have a special alias on line 22 of the &lt;code&gt;.zshrc&lt;/code&gt; file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nb"&gt;alias &lt;/span&gt;&lt;span class="nv"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/mnt/c/Users/zhanx/AppData/Local/Programs/'Microsoft VS Code'/bin/code"&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;With this alias, we can now use the &lt;code&gt;code&lt;/code&gt; command inside WSL 2 as we would in any local shell terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Zsh History Search &amp;amp; Starship
&lt;/h3&gt;

&lt;p&gt;With a ton of experiments, some of which can be seen in &lt;a href="https://github.com/starship/starship/issues/1038" rel="noopener noreferrer"&gt;this GitHub issue&lt;/a&gt;, my zsh with oh-my-zsh was proven to be slow in WSL 2. Slower than I would like, at least. I used to be a big fan as it really helps configure a nice and usable zsh out of the box. However, it includes too many things under the hood which I don't really need. Some of the features I would really like to keep are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Menu-like options when hitting Tab, which is built-in and can be enabled like shown at the beginning of my &lt;code&gt;.zshrc&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A nice-looking theme. I really like the &lt;a href="https://github.com/denysdovhan/spaceship-prompt" rel="noopener noreferrer"&gt;spaceship theme&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;History search with up arrow key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After searching for a while, I landed on &lt;a href="https://starship.rs/" rel="noopener noreferrer"&gt;starship&lt;/a&gt;, a Rust-powered and spaceship-inspired cross-shell prompt which also works with Powershell (Yay!!🤗), and this nice &lt;a href="https://github.com/zsh-users/zsh-history-substring-search" rel="noopener noreferrer"&gt;zsh-history-substring-search&lt;/a&gt; plugin. I installed the latter via &lt;a href="https://docs.brew.sh/Homebrew-on-Linux" rel="noopener noreferrer"&gt;homebrew&lt;/a&gt;. You can configure them just like I did at the end of the &lt;code&gt;.zshrc&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Typeface &amp;amp; Nerd Font
&lt;/h3&gt;

&lt;p&gt;As you would expect from a spaceship theme user, I like icons and emojis. However, not all emojis look nice in every terminal on every OS. On the other hand, nerd font icons are much are consistent and renders nicer in VS Code's built-in terminal. You can find &lt;a href="https://starship.rs/presets/" rel="noopener noreferrer"&gt;a preset config from starship&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A nice typeface is also critical to a nice CLI experience. As a diehard Consolas fan, I've always been looking around for an open-source alternative that I can use across all systems. Luckily, that mission was recently accomplished: &lt;a href="https://fontsarena.com/code-new-roman-by-sam-radian/" rel="noopener noreferrer"&gt;Code New Roman&lt;/a&gt; and its nerd font version &lt;a href="https://www.nerdfonts.com/font-downloads" rel="noopener noreferrer"&gt;CodeNewRoman Nerd Font&lt;/a&gt;. Give them a try if you share the love for Consolas!&lt;/p&gt;

&lt;h2&gt;
  
  
  Python &amp;amp; Node
&lt;/h2&gt;

&lt;p&gt;As you might have noticed, I use &lt;a href="https://docs.conda.io/en/latest/miniconda.html" rel="noopener noreferrer"&gt;miniconda&lt;/a&gt; and &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;nvm&lt;/a&gt; for managing Python and node/npm versions. You can install them simply by running:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# miniconda&lt;/span&gt;
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh ./Miniconda3-latest-Linux-x86_64.sh

&lt;span class="c"&gt;# nvm&lt;/span&gt;
wget &lt;span class="nt"&gt;-qO-&lt;/span&gt; https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
&lt;span class="c"&gt;# and add the nvm-related scripts to your .zshrc&lt;/span&gt;
nvm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--lts&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you know Anaconda, miniconda is just a stripped-down version of it. I like using it because of its separation from the system Python: I don't need to worry about breaking some system packages when I upgrade my Python installation. Conda, the dependency manager miniconda uses, can also identify packages that need upgrade and resolve conflicts when you bump up the Python version. At the time of writing, miniconda only comes with Python 3.7. However, you can easily upgrade to Python 3.8 by:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

conda &lt;span class="nb"&gt;install &lt;/span&gt;&lt;span class="nv"&gt;python&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3.8


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you want to upgrade, please do this right after installing miniconda as I've experienced some failures with a dozen packages already installed. For my purpose, Django already support Python 3.8 since 2.2.8 so it's safe to make the upgrade.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web &amp;amp; Database
&lt;/h2&gt;

&lt;p&gt;Here comes the (a bit) more tricky part. IIRC, previously in WSL 1, you can access the host (Windows) database from inside WSL. Due to the architecture change in WSL 2, you are not able to do that out of the box. Here in &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/wsl2-ux-changes#accessing-network-applications" rel="noopener noreferrer"&gt;this section&lt;/a&gt; it says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To access a Windows network application you'll need to use the IP address of your host machine.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can do so by &lt;code&gt;cat /etc/resolv.conf&lt;/code&gt; inside WSL, copy the IP address following "nameserver" and use it in your CLI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe9pjbnpswbmfbemman9z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe9pjbnpswbmfbemman9z.png" alt="zsh accessing Windows network application"&gt;&lt;/a&gt;&lt;br&gt;
Easy enough for web services. But what about database? Well, here you have two options.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install Database in WSL
&lt;/h3&gt;

&lt;p&gt;One of the more straightforward option is to install your database server inside your WSL 2. It is just the same as installing your database on any Ubuntu-based distro. As for my project, I use MariaDB and you can find &lt;a href="https://downloads.mariadb.org/mariadb/repositories/#distro=Ubuntu&amp;amp;distro_release=bionic--ubuntu_bionic&amp;amp;mirror=homelab&amp;amp;version=10.4" rel="noopener noreferrer"&gt;the official instructions here&lt;/a&gt;. You will be able to start the database server with &lt;code&gt;sudo service mysql start&lt;/code&gt;. The problem comes after the installation: How do I inspect the database with my favorite GUI tools like DataGrip/DBeaver/Sequel Pro from Windows?&lt;/p&gt;

&lt;p&gt;First, if you have a database server running on you Windows host, make sure to change either one of the ports your database is running on. Then, bind your WSL 2 database to the address &lt;code&gt;0.0.0.0&lt;/code&gt;. These settings can be applied by adding the following lines to your &lt;code&gt;/etc/mysql/my.cnf&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: I just tested with the latest WSL2 and MariaDB and it seems the &lt;code&gt;bind-address=0.0.0.0&lt;/code&gt; is no longer necessary.&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;

&lt;span class="nn"&gt;[mysqld]&lt;/span&gt;
&lt;span class="py"&gt;port&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3307&lt;/span&gt; &lt;span class="c"&gt;# or any port you like&lt;/span&gt;
&lt;span class="py"&gt;bind-address&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After editing, make sure to restart the database server by &lt;code&gt;sudo service mysql restart&lt;/code&gt;. Now you should be able to access your WSL database via &lt;code&gt;127.0.0.1:3307&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessing Database Running on Windows from WSL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; I personally don't recommend this approach because it requires much more workaround.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Warning&lt;/strong&gt;: This approach relies on the IP addresses on both the host and guest machine pointing to each other. As &lt;a href="https://github.com/microsoft/WSL/issues/4619#issuecomment-592482735" rel="noopener noreferrer"&gt;Uzume stated here&lt;/a&gt;, WSL 2 acts more like a virtual machine compared to WSL 1. &lt;strong&gt;HOWEVER, these IP addresses are NOT fixed!&lt;/strong&gt; They change on every reboot so you have to reconfigure something every time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frk0vznh0js0dgx9830pr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frk0vznh0js0dgx9830pr.png" alt="wsl 2 and win10 ip communication"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As shown in the graph above, in the current setting, WSL 2 can access Windows application via &lt;code&gt;172.21.64.1&lt;/code&gt;, which is the IP address in &lt;code&gt;/etc/resolv.conf&lt;/code&gt;. By default, Windows share the &lt;code&gt;127.0.0.1&lt;/code&gt; with WSL 2 and can access network applications running in WSL 2 via &lt;code&gt;127.0.0.1:&amp;lt;port&amp;gt;&lt;/code&gt; as shown above. You may wonder, "Well, what's the use of that &lt;code&gt;172.17.131.186&lt;/code&gt; in this case and where does it come from?" 🤔&lt;/p&gt;

&lt;p&gt;That's a great question. Databases, out of security consideration, do not allow remote access by default. You have to manually grant remote access to specified IP addresses if you want to do so. Let's first try to connect to the MariaDB running on Windows from WSL 2 first and see what will happen:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Inside WSL 2&lt;/span&gt;
mysql &lt;span class="nt"&gt;-u&lt;/span&gt; root &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-h&lt;/span&gt; 172.21.64.1 &lt;span class="se"&gt;\ &lt;/span&gt;&lt;span class="c"&gt;# replace1 172.21.64.1 with your own IP address in /etc/resolv.conf&lt;/span&gt;
  &lt;span class="nt"&gt;-p&lt;/span&gt; windows_db &lt;span class="c"&gt;# replace windows_db with your own db name&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;At this point, you will likely encounter some error message like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Inside WSL 2&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; mysql &lt;span class="nt"&gt;-u&lt;/span&gt; local_pr &lt;span class="nt"&gt;-h&lt;/span&gt; 172.21.64.1 &lt;span class="nt"&gt;-p&lt;/span&gt; windows_db
Enter password:
ERROR 1130 &lt;span class="o"&gt;(&lt;/span&gt;HY000&lt;span class="o"&gt;)&lt;/span&gt;: Host &lt;span class="s1"&gt;'172.17.131.186'&lt;/span&gt; is not allowed to connect to this MariaDB server


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here we get &lt;code&gt;172.17.131.186&lt;/code&gt;, the IP address of our WSL 2 virtual machine on Windows. Seeing this error message is actually a good sign as it indicates you can hit the database but just don't have the access right. What you need to do now is to configure your database server for remote access and grant access to your WSL 2's IP address &lt;code&gt;172.17.131.186&lt;/code&gt;. For MariaDB, the instructions can be found &lt;a href="https://mariadb.com/kb/en/configuring-mariadb-for-remote-client-access/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Following the instructions, we start the MySQL client command prompt, log in and type:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Inside MySQL Client on Windows&lt;/span&gt;
GRANT ALL PRIVILEGES ON windows_db.&lt;span class="k"&gt;*&lt;/span&gt; TO &lt;span class="s1"&gt;'local_pr'&lt;/span&gt;@&lt;span class="s1"&gt;'172.17.131.186'&lt;/span&gt; IDENTIFIED BY &lt;span class="s1"&gt;'my-new-password'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c"&gt;# again, replace the db name, ip address and password to your local ones&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You might need to restart the MariaDB server for it to take effect. If all goes well, you can now access the Windows MariaDB from WSL 2:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# Inside WSL 2&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; mysql &lt;span class="nt"&gt;-u&lt;/span&gt; local_pr &lt;span class="nt"&gt;-h&lt;/span&gt; 172.17.128.1 &lt;span class="nt"&gt;-p&lt;/span&gt; local_pr
Enter password:
Reading table information &lt;span class="k"&gt;for &lt;/span&gt;completion of table and column names
You can turn off this feature to get a quicker startup with &lt;span class="nt"&gt;-A&lt;/span&gt;

Welcome to the MariaDB monitor.  Commands end with &lt;span class="p"&gt;;&lt;/span&gt; or &lt;span class="se"&gt;\g&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Your MariaDB connection &lt;span class="nb"&gt;id &lt;/span&gt;is 15
Server version: 10.4.12-MariaDB mariadb.org binary distribution

Copyright &lt;span class="o"&gt;(&lt;/span&gt;c&lt;span class="o"&gt;)&lt;/span&gt; 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type &lt;span class="s1"&gt;'help;'&lt;/span&gt; or &lt;span class="s1"&gt;'\h'&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;help. Type &lt;span class="s1"&gt;'\c'&lt;/span&gt; to clear the current input statement.

MariaDB &lt;span class="o"&gt;[&lt;/span&gt;local_pr]&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now you can put the database host info in your web app's settings. For example, in Django's setting file:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="n"&gt;DATABASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;default&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;br&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ENGINE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;django.db.backends.mysql&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;NAME&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;local_pr&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;USER&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;local_pr&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PASSWORD&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;my-new-password&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;HOST&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;172.21.64.1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;PORT&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3306&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;br&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;&lt;br&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  VS Code&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Microsoft really provides great tooling for your development workflow on WSL. No surprice, my editor of choice is VS Code. For remote development using WSL, check out &lt;a href="https://code.visualstudio.com/docs/remote/wsl#_wsl-specific-settings" rel="noopener noreferrer"&gt;this guide&lt;/a&gt; if you haven't. Not everything applies to WSL 2 just yet but it's still a nice guide. What we need most is the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl" rel="noopener noreferrer"&gt;Remote - WSL&lt;/a&gt; extension. With it installed, we can now go to any working directory, type &lt;code&gt;code .&lt;/code&gt;, open up VS Code and start working. Install the extensions you need and enjoy the Linux dev workflow on Windows!&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this post I discussed how to set up WSL 2 for web development (Django and Vue in my case). Aspects covered include setting up zsh without the dependency on oh-my-zsh, installing Python and Node, and setting up the database for web development.&lt;/p&gt;

&lt;p&gt;Finally, a big THANK YOU to the awesome folks behind the WSL project! 💖 Thanks for making this possible and I really look forward to the first official release!&lt;/p&gt;

&lt;p&gt;I hope you find this post helpful. Thanks for stopping by!&lt;/p&gt;

</description>
      <category>wsl</category>
      <category>tooling</category>
    </item>
  </channel>
</rss>
