安裝 WSL2
啟用子系統和虛擬機平台 然后重啟系統
WSL 2 要求系統版本應該在 Windows 10, Version 2004, Build 19041 及以上。
以管理員身份打開 powershell,運行如下命令以啟動需要的組件:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
然后重啟。並且在 此處 下載並安裝適用於 x64 計算機的最新 WSL2 Linux 內核更新包。
打開 powershell,運行如下命令以將 wsl 的默認版本設置為 WSL 2:
wsl --set-default-version 2
更新WSL
wsl.exe --update
安裝 Arch WSL
在yuk7/ArchWSL - releases下載 Arch.appx / Arch.zip,解壓,雙擊 Arch.exe 進行安裝。詳見ArchWSL documentation。
更換國內鏡像源
PS: 以下部分都以 root 用戶身份運行命令
passwd # 設置密碼
# 設置軟件源
echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist
echo 'Server = https://mirrors.neusoft.edu.cn/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist
啟用 multilib 庫
multilib 庫包含 64 位系統中需要的 32 位軟件和庫。
vim /etc/pacman.conf,取消這幾行的注釋:
[multilib]
Include = /etc/pacman.d/mirrorlist
並且取消該文件中 #Color 這一行的注釋,以啟用彩色輸出。
添加 archlinuxcn 源
Arch Linux 中文社區倉庫 是由 Arch Linux 中文社區驅動的非官方用戶倉庫。包含中文用戶常用軟件、工具、字體/美化包等。
vim /etc/pacman.conf
在文件末尾加上:
[archlinuxcn]
Server = https://mirrors.aliyun.com/archlinuxcn/$arch
其他的見 https://github.com/archlinuxcn/mirrorlist-repo 最好是用自己學校的
然后:
# 初始化 keyring
pacman-key --init
pacman-key --populate
pacman -Syu # 更新
pacman -S archlinuxcn-keyring
pacman -Syy # 更新
創建用戶
注:此處的 yourname 是你要創建的用戶名
1. 新建用戶。-m 為用戶創建家目錄;-G wheel 將用戶添加到 wheel 用戶組
useradd -m -G wheel yourname
2. 設置密碼
passwd yourname
3. 因為 visudo 需要 vi
ln -s /usr/bin/vim /usr/bin/vi
4. 編輯 /etc/sudoers
visudo
將以下兩行行首的#去掉
# %wheel ALL=(ALL) ALL
# %wheel ALL=(ALL) NOPASSWD: ALL
在 powershell 中進入到 Arch.exe 所在文件夾,設置 WSL 默認登陸用戶和默認的 WSL:
.\Arch.exe config --default-user yourname
wsl -s Arch
重新打開,就是在 yourname 用戶了。
安裝常用軟件
安裝 yay
sudo pacman -S --needed base-devel
出現:: fakeroot is in IgnorePkg/IgnoreGroup. Install anyway? [Y/n],選 n,接下來一直回車即可。
sudo pacman -S --needed yay
yay 換源
yay --aururl "https://aur.tuna.tsinghua.edu.cn" --save
安裝 ZSH
安裝 Terminal 字體
給 windows 安裝以下字體,並且改變 windows terminal 的字體設置(這里就不細說了):
MesloLGS NF powerlevel10k 作者推薦
FiraCode NF 我更喜歡這個
sudo pacman -S zsh
安裝 OH MY ZSH
# 第一步 → 把 oh-my-zsh 項目 Clone 下來:
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
# 第二步 → 復制 .zshrc
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
# 第三步 → 更改你的默認 Shell
chsh -s /bin/zsh
推薦ZSH插件
可以參考
使用 proxychains 代理終端程序
可以使用 windows 的 qv②ray/clash/ssr 等代理軟件來代理 wsl 中的程序!先安裝 proxychains:
sudo pacman -S proxychains-ng
首先,sudo vim /etc/proxychains.conf,將proxy_dns這一行注釋。(這樣能夠讓 proxychains 代理 yay)
如果用的是 WSL 1,那就 sudo vim /etc/proxychains.conf,將最后一行的 socks4 127.0.0.1 9095 修改為:
socks5 127.0.0.1 1080
這個 1080 是我的 ssr 的 HTTP 端口號,改成你自己的。如果你用的是 WSL 2,由於目前 WSL 2 和 windows 的 ip 不同,我們需要先cp -f /etc/proxychains.conf /.proxychains.conf,然后在/.zshrc中添加以下內容:
# 獲取windows的ip
export WIN_IP=`cat /etc/resolv.conf | grep nameserver | awk '{print $2}'`
# 刪除 ~/.proxychains.conf 中 [ProxyList] 所在行到文件末尾的全部內容
sed -i '/\[ProxyList\]/,$d' ~/.proxychains.conf
# 往文件末尾添加socks5/http設置,這個 1080 是我的 qv②ray 的 socks5/http 端口號,改成你自己的
echo '[ProxyList]\nhttp '${WIN_IP}' 1080' >> ~/.proxychains.conf
# 設置別名;使用 ~/.proxychains.conf 作為proxychains的配置文件;讓proxychains quiet(不輸出一大串東西)
alias pc='proxychains4 -q -f ~/.proxychains.conf'
# 用來手動開關代理,建議走 http 協議,因為 wget 不支持 socks5
my_proxy=http://${WIN_IP}:1080
alias p-on='export all_proxy='${my_proxy}' http_proxy='${my_proxy}' https_proxy='${my_proxy}''
alias p-off='unset all_proxy http_proxy https_proxy'
然后:
# 在 yourname 用戶中
sudo ln -s ~/.proxychains.conf /root/.proxychains.conf
source ~/.zshrc
如果你發現還是無法代理,那可能是因為你的代理軟件沒打開允許來自局域網的連接
選項
注:pc ping google.com是沒有效果的,因為 proxychains 只會代理 TCP。
Tips
ArchLinuxx目錄 從文件資源管理器 \\wsl$
訪問
本文到這里就結束了,有疑問歡迎評論哦😉