Combined with Windows Terminal and WSL2, Linux development environment can be well combined with WIN platform, coupled with the support of Arch, it is really cool to burst.

The general idea is to first install Windows Terminal in Win, and start WSL2, then install ARCH, set X Server, and finally happy Coding.

Windows Terminal

Search and download in the Microsoft Store, can be modified, refer to Windows Terminal

My basic configuration is as follows, mainly setting the font and turning on the transparency.

{
    "$schema": "https://aka.ms/terminal-profiles-schema"."defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}"."copyOnSelect": false."copyFormatting": false."profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
            "colorScheme": "One Half Dark"."fontFace": "FiraCode Nerd Font"."fontSize": 11."padding": "0, 0, 0, 0"."useAcrylic": true."acrylicOpacity": 0.8."cursorShape": "emptyBox"."antialiasingMode": "cleartype",},"list": [{// Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}"."name": "Windows PowerShell"."commandline": "powershell.exe"."hidden": false
            },
            {
                // Make changes here to the cmd.exe profile.
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}"."name": "Command Prompt"."commandline": "cmd.exe"."hidden": false
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}"."hidden": false."name": "Azure Cloud Shell"."source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{a5a97cb8-8961-5535-816d-772efe0c6a3f}"."hidden": false."name": "Arch"."source": "Windows.Terminal.Wsl"."startingDirectory": "//wsl$/Arch/home/kiven/"."icon": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Archlinux-icon-crystal-64.svg/1200px-Archlinux-icon-crystal-6 4.svg.png"
            },
            {
                "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}"."hidden": false."name": Ubuntu 20.04 ""."source": "Windows.Terminal.Wsl"."startingDirectory": "/ / WSL $/ Ubuntu 20.04 / home/kiven/"}},// Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [].// Add custom actions and keybindings to this array.
    // To unbind a key combination from your defaults.json, set the command to "unbound".
    // To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
    "actions":
    [
        // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
        // These two lines additionally bind them to Ctrl+C and Ctrl+V.
        // To learn more about selection, visit https://aka.ms/terminal-selection
        { "command": {"action": "copy"."singleLine": false }, "keys": "ctrl+c" },
        { "command": "paste"."keys": "ctrl+v" },

        // Press Ctrl+Shift+F to open the search box
        { "command": "find"."keys": "ctrl+shift+f" },

        // Press Alt+Shift+D to open a new pane.
        // - "split": "auto" makes this pane open in the direction that provides the most surface area.
        // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
        // To learn more about panes, visit https://aka.ms/terminal-panes
        { "command": { "action": "splitPane"."split": "auto"."splitMode": "duplicate" }, "keys": "alt+shift+d"}}]Copy the code

wsl2

Wsl2 requires that the system version should be in Windows 10, Version 2004, Build 19041 and above.

You can enable the WSL by using the Control Panel -> Programs -> Enable or Disable Windows Features -> Select Windows Subsystem and VM Platform for Linux, or start PowerShell as an administrator and run the following command to start the required components

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Copy the code

After the restart, you need to download and install the latest WSL2 Linux kernel update package for your X64 computer here.

Finally, open Powershell and run the following command to set the default version of WSL to WSL2

wsl --set-default-version 2
Copy the code

In a nutshell, the difference between WSL and WSL2 is that WSL implements Linux functionality in the form of instruction translation, while WSL2 is based on hyper-V virtualization technology.

Arch

I won’t bore you with the appeal of Arch.

Install the arch WSL

Download Arch.zip in Yuk7 / ARCHWSL-Releases and install it according to yuk7/ ARCHWsl-Wiki.

In the source update

Once inside arch WSL, execute the following command (as root)

passwd  Set root password
Copy the code

Open /etc/pacman.d/ mirrorList with vim or nano and uncomment the source under China.

Run the following command

Initialize keyRing
pacman-key --init
pacman-key --populate
pacman -Syu
Copy the code

Open /etc/pacman.conf with vim, uncomment #Color and add it to the end of the file

[archlinuxcn]
Server = https://mirrors.aliyun.com/archlinuxcn/$arch
Copy the code

Run the following command

pacman -Syy
pacman -S archlinuxcn-keyring
Copy the code

Create a user

Common users can perform this operation to prevent Linux from running improperly.

-g wheel Add user to wheel user group
useradd -m -G wheel <youname>
# set password
passwd <youname>
Copy the code

Edit /etc/sudoers to uncomment # $wheel ALL=(ALL) ALL so that wheel group users can use root permissions.

In Powershell, go to the arch. exe folder and set the default WSL login user and the default WSL

.\Arch.exe config --default-user <youname>
wsl -s Arch
Copy the code

Installing Common Software

# Basic Linux command set
sudo pacman -S base-devel
# yay
sudo pacman -S yay
# yay for source
yay --aururl "https://aur.tuna.tsinghua.edu.cn" --save
# Other common commands
sudo pacman -S neofetch lolcat bat tree
# git openssh man-pages
sudo pacman -S git openssh man-pages
Install firacode font
sudo pacman -S nerd-fonts-fira-code
Copy the code

Install the ZSH

sudo pacman -S zsh
Change the current user's default shell
chsh -s /bin/zsh
Copy the code
Using ZSH plugin for ANTIGEN Management
sudo yay -S antigen
Copy the code

Add to.zshrc

# Start antigen
# Load antigen -- plugin manager
source /usr/share/zsh/share/antigen.zsh
# Load oh-my-zsh
antigen use oh-my-zsh

antigen bundle git
antigen bundle zsh-users/zsh-completions; rehash
antigen bundle pip
antigen bundle command-not-found
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-autosuggestions

# Antigen done
antigen apply
# End antigen
Copy the code
Install Starship beautify command line prompt
sudo pacman -S starship
Copy the code

Refer to Starship and add it in.zshrc

eval "$(starship init zsh)"
Copy the code

Execute exec $SHELL to see the effect of the update.

Install the PyQT5 environment

sudo pacman -S python python-pip
sudo pacman -S pyenv
sudo pacman -S python-pipenv
sudo pacman -S pyqt5
sudo pacman -S qt5-tools
Copy the code

Add to.zshrc

# set pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
Copy the code

Install the Node development environment

sudo pacman -S nvm
Copy the code

Add to.zshrc

source /usr/share/nvm/init-nvm.sh
Copy the code
Install Node V10.15NVM install v10.15.0Set the default versionNVM use v10.15.0Copy the code
# installation of yarn
sudo pacman -S yarn
# installation NRM
npm install -g nrm
# Check what sources are available
nrm ls
# Select Taobao Source
nrm usr taobao
Copy the code

Enable the X Server graphics environment

Windows installation VcXsrv

First, install VcXsrv on Windows

Locate the installation path of the software and perform operations on the two executable files vCXsrv.exe and xlaunch.exe: Right click -> Properties -> Compatibility -> Change High DPI Settings -> Check the Alternative High DPI scaling behavior to make VcXsrc look sharp on a high-resolution display.

Open xlaunch.exe by default. In the Extra Settings screen, check Disable Acess Control, enter -ac in Additional Parameters for VcXsrv, and save the configuration file. You can then double-click the file to start directly or move it to the Startup folder.

Configuration of the arch

First you need to install xorg
sudo pacman -S xorg xorg-xinit
Copy the code

Add to.zshrc

# wsl settings
export DISPLAY=`cat /etc/resolv.conf | grep nameserver | awk '{print $2}'`:0
export LIBGL_ALWAYS_INDIRECT=1
Copy the code

Configure the display output address

Edit /etc/x11/xwrapper. config to modify or add

allowed_users=anybody
Copy the code

You can then use the Xeyes command to test whether the display works.

The problem

Most of the problems can be solved by referring to Known issues.

Select One Large Window for some GUIs that cannot be rendered in the MULTI Window mode of VCXSRV, such as DWM.

The last

At this point, the basic environment is set up, arch can be used in WIN, and you can also use win commands in ARCH, such as code. To open vscode, you can also use explorer. Open Windows Explorer, you can also download Docker Desktop in Windows, and then use Docker directly in ARCH, which is very convenient.

reference

  • Arch Linux WSL2 configuration records
  • Known issues
  • Basic environment construction