Use WSL to Build a Development Environment

Develop gracefully on Windows

2 years ago
6 min


What is WSL

The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that enables you to run native Linux command-line tools directly on Windows, alongside your traditional Windows desktop and modern store apps.

What are the advantages of WSL

  • WSL requires fewer resources (CPU, memory, and storage) than a full virtual machine.
  • WSL allows you to run Linux command-line tools and apps alongside your Windows command-line, desktop and store apps, and to access your Windows files from within Linux.
  • Bash support strengthens the value of the command-line on Windows, allowing PowerShell to leverage other popular technologies.
  • WSL shares the IP address of Windows.

Which linux distributions have I used

In the end, I choose to use ArtixWSL and Ubuntu in this tutorial.

The reasons are as followed.

  • Why not?
    • Debian : It is very good, but the software is too old.
    • openSUSE Leap 42 : I am not very familiar with it, and need to work with the graphical interface to be more useful.
    • ArchWSL : Neither installing VScode nor atom will work properly. According to issues, this may be caused by electron (I'm not sure).
    • AlpineWSL : It is more suitable for deployment on small equipment, not for development.
  • Why?
    • Ubuntu : A WSL with the largest number of users and the most relevant tutorials is not easy to make mistakes. (But I hate it very much)
    • ArtixWSL : The derivative version of Arch Linux can get a similar experience without problems.



Package manager

Recommended open source mirror station:

WSL path: %\HOMEPATH%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

It is best not to modify the file under Windows. For details, please see here.

  • Ubuntu:
sudo vim /etc/apt/sources.list
# Modify the file according to the prompts of the open source station
sudo apt-get update && sudo apt-get upgrade  # Update
  • Aritx:
vim /etc/pacman.d/mirrorlist
# Modify the file according to the prompts of the open source station
vim /etc/pacman.conf  # Open the settings file
# Modify SigLevel = Never
pacman -Syu  # Update
pacman -S base git openssh sudo binutils wget  # Install the base components

Terminal Environment

Install zsh to replace Bash.

sudo apt install zsh  # Ubuntu
sudo pacman -S zsh  # Artix
sudo chsh -s $(which zsh)  # Use zsh as the default shell environment (optional)

Install oh-my-zsh to make the terminal more beautiful.

sh -c "$(curl -fsSL"

Please refer to here for the settings of oh-my-zsh.

You may find that the font does not display properly. For the normal display of the font, we also need to do the following.

  1. Enter Control Panel in the Explorer.
  2. Region - Administrative - Change system localeRegion
  3. win + r , Enter regedit.
  4. Go to Computer\HKEY_CURRENT_USER\Console.
  5. Find your terminal and add a REG_DWORD with the name CodePage and a value of fde9.
  6. Install Powerline Fonts or Programmer Font or Awesome-Powerline Fonts or Nerd-Fonts.
  7. Right click on the terminal - Properties to view the current encoding and modify the font. Properties


Add Port 222 and PasswordAuthentication yes to /etc/ssh/sshd_config.

# The following is only for Artix
sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
sudo ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

start ssh

sudo /usr/bin/sshd -D  # Artix
sudo service ssh start  # Ubuntu


git config --global "username"  # username
git config --global "email"  # email
git config --global http.proxy 'socks5://$端口号'  # HTTP proxy (optional)
git config --global https.proxy 'socks5://$端口号'  # HTTPS proxy (optional)

AUR helper

The following operations are only for Artix

Please install the C++ environment first

The complete AUR helper list, I choose yay for a simple reason - it is written in the Go language.

AUR helper does not run under the root user, so let's create a new user first.

# Create a user named artix
useradd -m -g users -G wheel -s /bin/bash artix
# Set the password for artix
passwd artix
# Set artix to root group
sudo vim /etc/sudoers
# Add a new line
artix ALL=(ALL) ALL
# Switch user
su - artix

install yay.

sudo chmod a+r /etc/pacman.conf
sudo chmod a+r /etc/pacman.d/mirrorlist
git clone
cd yay
makepkg -si

Use zsh/bash instead of windows terminal

I want to execute bash in windows, the format is as follows.

bash -c "sudo apt-get update"

To execute the windows program in bash/zsh, just add .exe to the end.


It's time to discard cmd and Powershell.

Develop under Winodws

Environmental Installation

  • C/C++
sudo apt-get install build-essential cmake gcc clang gdb lldb  # Ubuntu
sudo pacman -S make cmake gcc clang gdb lldb  # Artix
  • Python
sudo apt-get install python3 python3-pip  # Ubuntu
sudo apt-get install python python-pip
sudo pacman -S python python-pip python-pipenv  # Artix
sudo pacman -S python2 python2-pip python2-pipenv
# Common package (optional)
sudo apt-get install python-scipy python-numpy python-matplotlib python-pandas  # Ubuntu
sudo pacman -S python-scipy python-numpy python-matplotlib python-pandas   # Artix
  • Node.js
sudo apt-get install npm yarn nodejs  # Ubuntu
sudo pacman -S npm yarn nodejs  # Artix

However, I do not recommend this installation method. It is recommended to use nvm.


  • Git

Using WSLGit, we can use Git for linux on the Windows side.

Once the download is complete, open settings.json.

  "git.path": "C:\\CHANGE\\TO\\PATH\\TO\\wslgit.exe"

Add a value WSLGIT_USE_INTERACTIVE_SHELL to the environment variable and set it to 0 or false. This will not call Shell when used, improving efficiency.


  • C/C++

I believe that most people have used tools like MSYS2 and Cygwin. The configuration of WSL is similar. Just add the pipe-program and path-mapping in launch.json.

  "pipeTransport": {
    "pipeCwd": "",
    "pipeProgram": "c:\\windows\\sysnative\\bash.exe",
    "pipeArgs": ["-c"],
    "debuggerPath": "/usr/bin/gdb"
  "sourceFileMap": {
    "/mnt/c": "c:\\"

Also make sure that the value of externalConsole is flase , otherwise debugging will not work.

  • Python

The current official plugin is on the way: Issue #68293.

A viable solution comes from here.


Clion 2018 will be able to support WSL. If you are using a third-party distribution, please open %\HOMEPATH%\.CLion2019.1\config\options\wsl.distributions.xml and at the same time open the registry and go to Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\ and make sure that both ID and path are the same.


And make sure the following plugins are turned on.


Select WSL in Environment in Toolchains to enable the ssh connection.


But unfortunately, if you are using Artix, this doesn't work.


We can only use WSL as a remote host.


There is no significant difference in efficiency between the two methods, but using Remote Host will generate temporary files.


The setting of PyCharm is the same as Clion, modify %\HOMEPATH%\.PyCharm2019.1\config\options\wsl.distributions.xml.

There are also two options in Project Interpreter.


If you use Remote Host, you need to set the path mappings.


But if your path contains Chinese, this may result in an error, because it uses the ASCII character.

The solution is to set Mappings in Development.


Develop under WSL

To develop under WSL, you must have a graphical interface. Although the official has never officially supported GUI applications, it has been proven by countless people to be viable (although a lot of mistakes will be reported).

We will use X Window System. It contains X Server and X Client.

X Server

I have used Xming, VcXsrv, MobaXterm, X410.

The best experience is X410, which allows me to experience the smoothness of a near-native system. The official description is as follows.

X410 utilizes the source codes from the X.Org open-source project. However, unlike other products from different companies, we've removed the dependencies on Cygwin libraries and streamlined the codes.

Unfortunately, this is a paid software. I recommend to use free trial before you decide whether to buy it.

Free software I recommend VcXsrv.

X Client

sudo apt-get install xorg  # Ubuntu
sudo pacman -S xorg xorg-xinit  # Artix

Then you can install the GUI application.


Visual Studio Code is my preference, because I can't find another software that can be both lightness like the Editor and powerful of the IDE.

# Ubuntu
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make  # Add source
sudo apt-get update  # Update list
sudo apt-get install ubuntu-make
umake web visual-studio-code
# Artix
# Choose one of them, it is recommended to use yay installation
pacman -S code
yay -S visual-studio-code-bin

Then you can start VSCode.

DISPLAY=:0 code  # short of DISPLAY=localhost:0 code
sudo DISPLAY=:0 code --user-data-dir  # Run as an root in order to be able to use git
# You can write the DISPLAY parameter to .profile so you don't have to write it every time.
echo 'export DISPLAY=:0.0' >> .profile

Chinese Font Installation

After opening, it is found that Chinese displays garbled characters. For this we need to install Chinese fonts.

The installation in Artix is very simple.

# This is the three fonts I recommend.
sudo pacman -S adobe-source-han-sans-cn-fonts
sudo pacman -S adobe-source-han-serif-cn-fonts
sudo pacman -S noto-fonts-cjk

The installation in Ubuntu is more troublesome. An opportunistic approach is to add C:\Windows\Fonts to the font directory. However, during use, I found that this would affect the font display under Windows and even cause the software to crash.

The correct way to do this is to move the font file to the Ubuntu directory and create a font index. You can refer to here.

Open settings.json in VSCode for a simple configuration. My configuration is as follows.

  "window.titleBarStyle": "custom",
  "editor.fontSize": 20,
  "editor.fontFamily": "'Source Code Pro', 'Source Code Pro Black', 'Source Code Pro Light', 'Source Code Pro Medium', 'Source Code Pro ExtraLigh', 'Source Code Pro Semibold'",
  "terminal.integrated.cursorBlinking": true,
  "terminal.integrated.fontFamily": "'DejaVuSansMono Nerd Font Mono', 'DejaVuSansMono Nerd Font', 'SauceCodePro Nerd Font Mono', 'SauceCodePro Nerd Font'",
  "terminal.integrated.fontSize": 16

The fonts involved are


yay -S nerd-fonts-source-code-pro
yay -S nerd-fonts-dejavu-complete
# choose one of two
sudo pacman -S adobe-source-code-pro-fonts
npm install git://

Jupyter Notebook

  • Installation
# python3
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pip -i  # Use Tsinghua Source
python3 -m pip install jupyter
python3 -m pip install jupyter -i  # Use Tsinghua Source
# python2
python -m pip install --upgrade pip
python -m pip install --upgrade pip -i  # Use Tsinghua Source
python -m pip install jupyter
python -m pip install jupyter -i  # Use Tsinghua Source
  • Running
jupyter notebook
sudo jupyter notebook --allow-root  # Run as an root

I mentioned Windows and WSL shared network ports before, so open http://localhost:8888 directly under Windows.


  • C/C++ (optional)

Compilation takes a long time and takes up a lot of space

Install Cling.

chmod +x
./ --check-requirements && ./ --create-dev-env Debug --with-workdir=./cling-build/

Add the Cling kernel to Jupyter Notebook.

export PATH=/cling-install-prefix/bin:$PATH
cd /cling-install-prefix/share/cling/Jupyter/kernel

pip3 install -e

jupyter-kernelspec install [--user] cling-cpp17
jupyter-kernelspec install [--user] cling-cpp1z
jupyter-kernelspec install [--user] cling-cpp14
jupyter-kernelspec install [--user] cling-cpp11

Software such as Eclipse and Clion can also be used, but I will not introduce it here.

High Level Operation

GUI Software for ssh Connection

Add X11Forwarding yes to /etc/ssh/sshd_config to enable X Server.

The desktop environment I installed has xfce4, mate, ghome, dde, of which the first three perform well, but dde does not work properly in debian and Ubuntu. One possible solution comes from Issue #637.

After the installation is successful, it can be opened in the terminal.

DISPLAY=:0 xfce4-session  # xfce4
DISPLAY=:0 mate-session  # mate
DISPLAY=:0 deepin-session  # dde

Remote Desktop

Install the daemon xrdp that supports Microsoft's Remote Desktop Protocol (RDP).

# Ubuntu
sudo apt-get install xrdp
sudo sed -i 's/port=3389/port=3390/g' /etc/xrdp/xrdp.ini  # Set port
sudo echo xfce4-session >~/.xsession  # Write the desktop environment
sudo service xr start  # Start service
# Artix
yay -S xrdp
sudo sed -i 's/port=3389/port=3390/g' /etc/xrdp/xrdp.ini  # Set port
sudo echo xfce4-session >~/.xsession  # Write the desktop environment
sudo usr/bin/xr  # Start service

Win + r run mstsc to connect localhost:3390.

If an error occurs, install one of the backends: Xvnc, X11rdp, xorgxrdp.


Docker currently only has a client running on WSL and can't run daemons. The mainstream solution on the Internet is to connect to a remote daemon via Docker CLI, such as Docker for Windows. But if you still need to open a virtual machine like hyper-v, it doesn't make sense to do so.

If you insist on using it, you can refer to this.

But now someone has successfully run Native Docker on WSL, although it is limited in functionality, such as the inability to use Docker Compose, it is still very exciting.

I only tried and succeeded on Ubuntu.


Run Ubuntu.exe as an administrator.

sudo apt-get remove docker docker-engine containerd runc # Uninstall old version
sudo apt-get update  # Update list

# Install packages to allow apt to use a repository over HTTPS
sudo apt-get install \\
    apt-transport-https \\
    ca-certificates \\
    curl \\
    gnupg-agent \\

# Add Docker’s official GPG key:
# The link can be replaced by Tsinghua source:
curl -fsSL | sudo apt-key add -

# Set up the stable repository
# The link can be replaced by Tsinghua source:
sudo add-apt-repository \\
    "deb [arch=amd64] \\
    $(lsb_release -cs) \\

sudo apt-get update
sudo apt-get install docker-ce
sudo service docker start  # 开启 docker

If you see Cannot connect to the Docker daemon ... Is the docker daemon running? after opening, please refer to Issue #2291.

Awesome Tools

  • wsl-open: Utility for opening files within the WSL command line in Windows GUI applications.
  • wslu: This is a collection of utilities for WSL.
  • Ansible-WSL: Provisioning your Windows by Ansible from WSL.
  • wsl-terminal: A terminal emulator for WSL,
  • LxRunOffline: A full-featured utility for managing WSL.

Here I specifically mention LxRunOffline. This is definitely a must-have tool for using WSL, the backup feature lets you toss arbitrary and protects systems like Arch.


Q :The WSL GUI application cannot switch directly to the windows application window after applying full screen.

A: There is no way to solve it, but you can create a new desktop dedicated to WSL. The shortcut keys for switching between different desktops are Win + Ctrl + ← and Win + Ctrl + →.

Q: How do I set the default distribution of WSL?

A : Execute wslconfig in Powershell. Not only can you set the default distribution, but you can also remove the distribution and change the default user. such as:

wslconfig /l  # Lists registered distributions.
wslconfig /u ubuntu   # Unregisters ubuntu
wslconfig /s ubuntu   # Sets ubuntu as the default.
wslconfig ubuntu config --default-user root   # Set the default user of ubuntu to root

Q: Why is WSL's CPU resource usage particularly high?

A: This is largely caused by Windows Defender. You can turn it off or add the WSL directory to whitelist.

Q: Why are some windows programs not open in bash?

A: By default, only the program in C:\Windows\System32 can be opened. To open other programs, please write ~/.profile. For example, export PATH="$PATH:/mnt/c/Program Files/PreSonus/Studio One 4/".

Q: The GUI application is too small for high-resolution screens.

A: The easiest solution is to set the zoom behavior of X Server under windows. But the fonts tend to be blurry.

The second solution is to execute the following instructions before output:

Export QT_SCALE_FACTOR=2 # for ≥ Qt 5.6 application, zoom 200%
Export GDK_SCALE=2 # for GDK 3 (GTK+ 3) app, zoom 200%

The third solution is for applications like VSCode, Atom developed by electron, you can directly set "window.zoomLevel": 4.

The fourth solution is based on the desktop environment you have installed and the DPI size set in Appearance - custom DPI setting.


Q :How do I change the display language of WSL?

A: This is an example:

Sudo update-locale LANG=en_US.UTF8


WSL makes development under Windows more comfortable. But many problems make it impossible to replace virtual machines or Docker, such as Do not support OpenCL & CUDA, can't use the full Native Docker and bad I/O performance.

And WSL (Linux) is the thing needs to be tossed, and it takes several failures to find the right one.

Love is the same.

Last modified on November 3rd 2020 4:55:53 pm
Douban Neighbor Analysis
Knuth–Morris–Pratt the KMP Algorithm
© 2020 · YXL
Build with Gatsby