Install & Use WSL2 on Windows 10

Install WSL2

Official guide from Microsoft can be found at here.

So you can turn off the page now:)

  1. Upgrade Windows 10 to education edition or above
    1. Refer to this site to get script to setting activation server to NJU kms.
    2. Or use anything you like to upgrade Windows, for example, a retail product key.
  2. Update Windows to at least Version 1903
  3. Right-click the Windows logo on the status bar and select Windows Powershell (Administrator) and run:
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  4. Download the Linux kernel update package from here
  5. Open Powershell and run
    wsl --set-default-version 2
    
  6. Reboot
  7. Install Ubuntu in Microsoft Store
    1. Search for and install Ubuntu
  8. Launch it, you will get a WSL console, type your username and password in it
  9. Change apt source to mirror.nju.edu.cn using vim
    1. sudo vim /etc/apt/sources.list
    2. Type in your password
    3. :%s/archive.ubuntu.com/mirror.nju.edu.cn/g
    4. :%s/security.ubuntu.com/mirror.nju.edu.cn/g
    5. :wq
    6. sudo apt update && sudo apt upgrade
  10. Install some useful utilities
    1. See below
    2. (You can introduce some other fancy tools to me)
  11. Enjoy

Or you can try the extremely advanced Arch Linux.

Updating the Windows Console Colors & Fonts

You can download an utility from here.

Run ColorTool.exe with argument -bx will change the color of both cmd and wsl consoles, you may need to set these properties for powershell consoles manually.

Or you can try to use the good-looking Windows Terminal from Microsoft Store.

Fonts for the command line

Probably the only good-looking font available for the command line is Sarasa Gothic(等距更纱黑体), you can get it from here.

Shell

You can use zsh, and use oh-my-zsh as it’s plugin manager.

I personally recommend these plugins:

  • zsh-syntax-highlighting
    • git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • zsh-autosuggestions
    • git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

And don’t forget to activate them in ~/.zshrc.

I personally use nicoulaj as the theme.

Set proxy

Assume that certain strange program is listening to the port 1083 at localhost.

Add these to ~/.zshrc.

declare winip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
declare http_port=1083
export DISPLAY="${winip}:0"
export ALL_PROXY="http://${winip}:${http_port}"
export HTTP_PROXY=$ALL_PROXY
export http_proxy=$ALL_PROXY
export HTTPS_PROXY=$ALL_PROXY
export https_proxy=$ALL_PROXY
if [ "`git config --global --get proxy.https`" != "${ALL_PROXY}" ]; then
        git config --global proxy.https "${ALL_PROXY}"
fi

Write a small script ~/.proxy-wrapper like this, don’t forget to chmod +x ~/.proxy-wrapper.

#!/bin/sh
declare winip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
declare socks5_port=1083

nc -x ${winip}:${socks5_port} -X5 $*

(We use openbsd-netcat here.)

Add these to ~/.ssh/config:

Host github github.com
    Hostname github.com
    User git
    ProxyCommand $HOME/.proxy-wrapper '%h %p'

Add these to ~/.gitconfig

[core]
    gitproxy = $HOME/.proxy-wrapper

You can refer to this site and this site for further infomation.

Git

git config --global user.name "Zhihui Zhao"
git config --global user.email "zhh.zhao@outlook.com"

You can refer to this site for further infomation.

Python

sudo apt install python-is-python3 python3-pip python3-tk
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

You can refer to this site for further infomation.

X11 Forward

I recommend using vcxsrv as a X11 server. You can get it from here.

Remember to disable access control, you can refer to this for more info.

Latex

I recommend using newest version of TeXLive using images from here. Remember to toggle create symlinks to standard directories before installation.

You can use this template to write your reports and homework.

If you want to directly use fonts installed in Windows, instead of copying them to Ubuntu, you can create /etc/fonts/local.conf as super user and write:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <dir>/mnt/c/Windows/Fonts</dir>
</fontconfig>

to it.

If using Arch Linux, you may want to install texlive-core texlive-extra texlive-langchinese texlive-science texlive-fontsextra texlive-bibtexextra

Ruby

sudo apt install ruby-full bundler
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
bundle config mirror.https://rubygems.org https://mirrors.tuna.tsinghua.edu.cn/rubygems

You can refer to this for further information.

Java

sudo apt install openjdk-11-jdk openjdk-8-jdk maven

Add these to ~/.m2/settings.xml:

<settings>
    <mirrors>
        <mirror>
            <id>aliyunmaven</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun public</name>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
        <mirror>
            <id>aliyun-central</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-central</name>
            <url>https://maven.aliyun.com/repository/central</url>
        </mirror>
        <mirror>
            <id>aliyun-spring</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-spring</name>
            <url>https://maven.aliyun.com/repository/spring</url>
        </mirror>
        <mirror>
            <id>aliyun-spring-plugin</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-spring-plugin</name>
            <url>https://maven.aliyun.com/repository/spring-plugin</url>
        </mirror>
        <mirror>
            <id>aliyun-apache-snapshots</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-apache-snapshots</name>
            <url>https://maven.aliyun.com/repository/apache-snapshots</url>
        </mirror>
        <mirror>
            <id>aliyun-google</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-google</name>
            <url>https://maven.aliyun.com/repository/google</url>
        </mirror>
        <mirror>
            <id>aliyun-gradle-plugin</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-gradle-plugin</name>
            <url>https://maven.aliyun.com/repository/gradle-plugin</url>
        </mirror>
        <mirror>
            <id>aliyun-jcenter</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-jcenter</name>
            <url>https://maven.aliyun.com/repository/jcenter</url>
        </mirror>
        <mirror>
            <id>aliyun-releases</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-releases</name>
            <url>https://maven.aliyun.com/repository/releases</url>
        </mirror>
        <mirror>
            <id>aliyun-snapshots</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-snapshots</name>
            <url>https://maven.aliyun.com/repository/snapshots</url>
        </mirror>
        <mirror>
            <id>aliyun-grails-core</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-grails-core</name>
            <url>https://maven.aliyun.com/repository/grails-core</url>
        </mirror>
        <mirror>
            <id>aliyun-mapr-public</id>
            <mirrorOf>*</mirrorOf>
            <name>aliyun-mapr-public</name>
            <url>https://maven.aliyun.com/repository/mapr-public</url>
        </mirror>
    </mirrors>
</settings>

You can refer to this and this for further information.

Visual Studio Code

Download Visual Studio Code at here.

Install a plugin named Remote - WSL and use it to get access to your WSL2.

Install A LOT OF plugins to write code in different languages happily.