本文最后更新于:2025年4月24日 下午
                  
                
              
            
            
              
              安装篇 
步骤 1 - 启用适用于
Linux 的 Windows 子系统 
需要先启用“适用于 Linux 的 Windows 子系统”可选功能,然后才能在
Windows 上安装 Linux 分发。
以管理员身份打开 PowerShell 并运行:
1 dism.exe /online  /enable-feature  /featurename :Microsoft-Windows-Subsystem-Linux  /all  /norestart 
步骤 2 - 检查运行 WSL 2
的要求 
若要更新到 WSL 2,需要运行 Windows 10。
对于 x64 系统:版本 1903 或更高版本,采用 内部版本 18362
或更高版本。
对于 ARM64 系统:版本 2004 或更高版本,采用 内部版本 19041
或更高版本。
低于 18362 的版本不支持 WSL 2
步骤 3 - 启用虚拟机功能 
安装 WSL 2 之前,必须启用“虚拟机平台”可选功能。
计算机需要虚拟化功能才能使用此功能。
以管理员身份打开 PowerShell 并运行:
1 dism.exe /online  /enable-feature  /featurename :VirtualMachinePlatform  /all  /norestart 
步骤 4 - 下载 Linux
内核更新包 
适用于 x64 计算机的
WSL2 Linux 内核更新包 
步骤 5 - 将 WSL 2
设置为默认版本 
打开 PowerShell,然后在安装新的 Linux 发行版时运行以下命令,将 WSL 2
设置为默认版本:
1 wsl --set -default -version 2 
步骤 6 - 安装自己喜欢的
Linux 版本 
在Microsoft Store搜索ubuntu,安装18.04
折腾篇 
设置用户名和密码 
首次启动设置用户名和密码
更换apt源为清华源 
编辑 /etc/apt/sources.list 删除所有内容,添加如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 # 默认注释了源码镜像以提高 apt update  速度,如有需要可自行取消注释deb  https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal main restricted universe multiversedeb -src https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal main restricted universe multiversedeb  https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-updates main restricted universe multiversedeb -src https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-updates main restricted universe multiversedeb  https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-backports main restricted universe multiversedeb -src https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-backports main restricted universe multiversedeb  https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-security main restricted universe multiversedeb -src https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-security main restricted universe multiversedeb  https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-proposed main restricted universe multiversedeb -src https: //mirrors.tuna.tsinghua.edu.cn /ubuntu/ focal-proposed main restricted universe multiverse
安装指定版本的nodejs和最新版npm 
用命令安装
1 2 3 4 5 6 7 curl -sL https:# 注意14代表版本号,可根据需要更换 get  install -y nodejs# v14.16.1 # 6.14.12 
nodejs14.16.1自带npm版本为6.14.12,可以通过命令升级npm为最新版
1 2 3 npm  install -g npm npm  -v
设置git配置 
全局配置git用户名和邮箱,如果要push到github,则跟github用户名和邮箱保持一致
1 2 3 4 5 6 git  config  --global  user .name  "xxxxx" git  config  --global  user .email  "xxx@gmail.com" git  config  --list  
安装配置Windows Terminal 
Windows Terminal
是win推出的一款新的命令行工具,可以在应用商店里搜索并下载安装
安装zsh 
1 2 3 4 5 # 安装 zsh get  install zsh# 修改默认的 Shell 为 zsh 
安装oh-my-zsh 
oh-my-zsh用于快速配置zsh,进入官网或者Github可以了解其基本使用及其丰富的主题使用,安装只需要执行下面代码即可
1 sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) " 
如果遇到443错误,可能是dns污染造成的,分步执行以下代码
1 2 wget https:// raw.githubusercontent.com/ohmyzsh/ ohmyzsh/master/ tools/install.sh
安装 zsh-syntax-higlighting 语法高亮插件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 //gi thub.com/zsh-users/ zsh-syntax-highlighting.git$ZSH_CUSTOM /plugins$ZSH_CUSTOM /plugins/ zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
安装 zsh-autosuggestions 语法历史记录插件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 //gi thub.com/zsh-users/ zsh-autosuggestions.git$ZSH_CUSTOM /plugins$ZSH_CUSTOM /plugins/ zsh-autosuggestions/zsh-autosuggestions.zsh
更改oh-my-zsh主题 
安装Powerline字体以使用图标
1 $ sudo apt install  fonts-powerline
将主题从'robbyrussell'改为'agnoster'为传奇的Oh-My-Zsh主题
1 2 vim ~/.zshrc /.zshrc 
如果看到有乱码出现的话,那就需要给windows安装powerline字体
详见https://blog.csdn.net/qiphon3650/article/details/109165495
安装完毕后(安装自己喜欢的几个字体就行了,没必要全装),配置Windows
Terminal字体为刚安装的字体
取消前面的用户名和主机名显示 方法一:
1 2 cd ~/.oh-my-zsh/ themes
把其中的 prompt_context 注释掉
这样,终端就不再显示前面长长的用户名和主机名了
方法二: 下面这个方法更好些: 修改 vim ~/.zshrc
文件,在文件底部增加 隐藏用户名和主机名
只保留用户名,隐藏主机名
1 2 3 4 5 prompt_context if  [[ "$USER "  != "$DEFAULT_USER "   -n "$SSH_CLIENT "  ]]; then "%(!.%{%F{yellow}%}.)$USER " fi 
只保留主机名,隐藏用户名
1 2 3 4 5 prompt_context if  [[ "$USER "  != "$DEFAULT_USER "   -n "$SSH_CLIENT "  ]]; then "%(!.%{%F{yellow}%}.)$HOST " fi 
修改后记得执行 source ~/.zshrc
安装autojump 
1 2 apt install auto jump
找到plugins,把autojump添加进去
1 2 3 4 5 6 plugins=(auto suggestionsauto jump
然后 source .zshrc
autojump就开始记录你进入过的目录,以后直接 j 目录名
就可以了,甚至是目录名的部分字母都可以,如果有多选,提供tab选择功能
解决windows
terminal连接ssh不能输入中文标点 
详情见https://zhiqiang.org/it/windows-terminal-cannot-type-chinese-punctuations-in-ssh.html
安装shadowsocks并在客户端使用 
https://shadowsockshelp.github.io/Shadowsocks/linux.html#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%AE%A2%E6%88%B7%E7%AB%AF 
1 2 apt-get install python-pip//gi thub.com/shadowsocks/ shadowsocks.git@master
创建一个 /etc/shadowsocks.json 文件,格式如下
1 2 3 4 5 6 7 8 9 10 {"server" :"服务器 IP 或是域名" ,"server_port" :端口号,"local_address" : "127.0.0.1" ,"local_port" :1080 ,"password" :"密码" ,"timeout" :300 ,"method" :"加密方式 (chacha20-ietf-poly1305 / aes-256-cfb)" ,"fast_open" : false 
启动:Python 版客户端命令是 sslocal
1 /usr/ local/bin/ sslocal -c /etc/ shadowsocks.json -d start
终端内使用,需安裝 proxychains
1 apt-get  install proxychains
编辑 /etc/proxychains.conf 修改最后一行
接着我们就可以直接 用 proxychains + 命令的方式使用代理,例如
1 2 3 proxychains curl  xxxxwget  xxxx-get  xxxx
关闭 Shadowsocks: 在终端内输入
kill 相应的 pid 即可
sslocal启动失败的来看 
如果你的ss加密方式是chacha20协议的,并且看到报错
1 load  libsodium failed with  path  None 
那就需要安装一下libsodium了
1 2 3 4 5 6 7 wget https:// download.libsodium.org/libsodium/ releases/LATEST.tar.gz
据说还有不用编译的安装方法,自行百度
配置Vim编辑器 
创建配置文件
将以下内容粘贴进去
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """" """ """"""vim 实用配置: https://www.xiebruce.top/594. html"""""" """ """ """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" " syntax on           " 语法高亮"退格键默认删除光标所在字符,但这样感觉怪怪的,所以我们可以设置它删除光标所在字符的前一个字符,看起来更符合直观的印象 set backspace=2 set number          " 显示行号,可简写为:set nu,取消:set nonu"光标所在行显示一条下划线 set hlsearch        " 高亮显示查询出来的结果"搜索的时候逐字高亮匹配 set ruler           " 光标移动时,编辑器底部显示当前行号与列号"不使用vi兼容模式 set autoread        " 文件改动时自动载入4        "一个tab所占列数 set softtabstop=4   " 敲入tab键时实际占有的列数"设置用空格代替tab set shiftwidth=4    " 底行模式下用:n,m>或:n,m<缩进时,缩进的列数256         "terminal Color 支持256色(默认是8色) hi comment ctermfg=6 " 设置注释颜色"解决vim中文乱码问题 set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 set termencoding=utf-8 set encoding=utf-8 set smartindent " 智能缩进(好处是修改代码时会根据代码规则自动缩进,坏处是当用`:n,m>` 对齐左侧的注释将不会被移动)"set autoindent " 自动缩进(这两个差不多,感觉在大括号自动配对时,用智能缩进好点)"自动补全单/双引号、圆、中、大括号 inoremap ' ''<ESC>i inoremap "  "" <ESC>i
Windows访问Linux子系统的文件 
由于wsl2系统是完整的一个vhdx磁盘文件,所以不能直接访问,可以通过添加网络位置的方式访问:
\\wsl$\Ubuntu-18.04 这一网络位置就代表了 WSL2
内部文件的地址,根据不同的发行版后缀可能会有所不同,如果你不知道叫什么,可以在命令行内输入
wsl --list 查看名称。
参考文献 
搜索了众多文章,由于完成此篇历时较久,未能一一记录下原文链接,侵权删。