Windows Subsystem for Linux [Quickly experience Linux with WSL 2 on Windows]

Introduction to WSL

The full name of WSL is Windows Subsystem for Linux, and the official website is translated as: Windows Subsystem for Linux (WSL)

Direct access to official documentation: Windows Subsystem for Linux Documentation | Microsoft Docs

Comparison between WSL1 and WSL2:
Insert image description here

Install WSL2

This installation environment:

Processor: Intel® Core™ i7-9750H CPU @ 2.60GHz 2.59 GHz
RAM: 16.0 GB (15.8 GB available)
System type: 64-bit OS, x64-based processor
Operating system: Windows 10 Professional

Note: WSL and Ubuntu have not been installed before this installation.

Check if it can be installed

Your computer needs to support Hyper-V virtualization.
To check whether it supports Hyper-V:

Open cmd and entersysteminfo

Check the Hyper-V information, as shown in the figure below, and it will be supported.
Insert image description here

Installation method one:

# 1.切换路径
cd D:\Linux\ubuntu20.04 
# 2.下载文件【时间较长】
Invoke-WebRequest -Uri https://wsldownload.azureedge.net/Ubuntu_2004.2020.424.0_x64.appx -OutFile Ubuntu20.04.appx -UseBasicParsing
# 3.
Rename-Item .\Ubuntu20.04.appx Ubuntu.zip
# 4. 
Expand-Archive .\Ubuntu.zip -Verbose 
# 5.
cd .\Ubuntu\ 
# 6.
.\ubuntu2004.exe

Insert image description hereInsert image description here

Installation method two:

wsl --install
# –install 命令执行以下操作:
#    启用可选的 WSL 和虚拟机平台组件
#    下载并安装最新 Linux 内核
#    将 WSL 2 设置为默认值
#    下载并安装 Ubuntu Linux 发行版(可能需要重新启动),默认是安装在 C 盘的(如果要安装其他盘可以看下面的操作)
# 注意:上述命令仅在完全未安装 WSL 时才有效,如果运行 wsl --install 并查看 WSL 帮助文本,
# 请尝试运行 wsl --list --online 以查看可用发行版列表并运行 wsl --install -d以安装发行版。
wsl --list --online
wsl --install -d Ubuntu-20.04
# 查看版本
wsl -l -v 

Update mirror source

# 进入linux终端执行
sudo vim /etc/apt/sources.list

Note:
Enter vim fileto enter the file; Enter :wqto save and exit the file.
Press the key ito enter the file editing mode; press the key escto exit the file editing mode;

Comment out the official sources and replace them with one of the following two (mine is Ubuntu20.04, other versions or sources can be searched online by yourself)

# 阿里云
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

# 清华
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

Uninstall wsl subsystem

# 首先查看本机安装了哪些子系统:
wsl --list --all
# unregister 注销
wsl --unregister <System_name>

Just go to its path and delete all the files.
Insert image description here

Install Windows Terminal

Windows Terminal can help us manage command line tools, PowerShell, WSL and other Shell user tools, and can provide us with the best WSL experience.
Click the download address to download
or go to the Microsoft Store (Microsoft Store) to find the keyword Windows Terminal. You
can also open the Microsoft App Store, search for "Terminal", and install it. The Terminal interface is as follows:
Insert image description here

Open Ubuntu terminal

Insert image description here

Install oh-my-zsh

Execute in terminal under ubuntu:

# 1.安装 zsh:
sudo apt update 
sudo apt install git zsh -y
chsh -s /bin/zsh
# 2.安装oh my zsh所需的字体
git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh
# 3.安装oh my zsh
cd ../
wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh  # 国内下载地址
# 3.1 给 install.sh 添加执行权限
chmod +x install.sh
# 3.2 修改 install.sh 的镜像
vi install.sh
#将以下
#		REPO=${REPO:-ohmyzsh/ohmyzsh}
#		REMOTE=${REMOTE:-https://github.com/${REPO}.git}
#更改为
#		REPO=${REPO:-mirrors/oh-my-zsh}
#		REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}
# 3.3 保存退出,执行 
./install.sh 

# 4.安装皮肤
vi ~/.oh-my-zsh/themes/agnoster.zsh-theme
#把 92 行修改为:
#		prompt_segment green black "%(!.%{%F{yellow}%}.)%n"

# 5.安装历史命令自动补全 & 高亮显示
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
# 5.1 安装完改一下配置文件
vim ~/.zshrc
# 5.2 把plugins中两个刚刚下载好的插件名字加进去(73行),然后保存退出
#		plugins=(git zsh-autosuggestions zsh-syntax-highlighting )
# 5.3 最后更新一下配置文件
source .zshrc

References:

How to use WSL 2 on Windows to quickly experience silky-smooth Linux

Guess you like

Origin blog.csdn.net/qq_41361442/article/details/131704180