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. Update Windows 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. Upgrade 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. Install Ubuntu in Microsoft Store
    1. Search for and install Ubuntu
  7. Launch it, you will get a WSL console, type your username and password in it
  8. Change apt source to mirrors.nju.edu.cn using vim
    1. sudo vim /etc/apt/sources.list
    2. Type in your password
    3. :%s/archive.ubuntu.com/mirrors.nju.edu.cn/g
    4. :%s/security.ubuntu.com/mirrors.nju.edu.cn/g
    5. :wq
    6. sudo apt update & sudo apt upgrade
  9. Install useful utilities
    1. See below
    2. (You can introduce some other fancy tools to me)
  10. Enjoy

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.

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 oh-my-zsh to install zsh:

I personally recommend these plugins:

I personally use nicoulaj as zsh theme.

Set proxy

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

Add these to ~/.zshrc.

winip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
export DISPLAY=$winip:0
export ALL_PROXY=http://$winip:1083
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`" != "http://$winip:1083" ]; then
        git config --global proxy.https http://$winip:1083
fi

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

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

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

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 refer to this

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.