結(jié)合 windows terminal
與 wsl2
儡蔓,可以很好地將 linux 開(kāi)發(fā)環(huán)境結(jié)合到 win 平臺(tái)下,再加上 Arch
的加持疼邀,簡(jiǎn)直爽到炸裂喂江。
總的思路是首先在 win 中安裝 windows terminal
,并開(kāi)啟 wsl2
旁振,然后安裝 arch
获询,設(shè)置 X server
,最后就是 happy coding
拐袜。
Windows Terminal
在微軟商店中搜索下載即可吉嚣,可稍作修改,參考 Windows Terminal
我的基本配置如下阻肿,主要設(shè)置了字體以及開(kāi)啟了透明度瓦戚。
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"copyOnSelect": false,
"copyFormatting": false,
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
"colorScheme": "One Half Dark",
"fontFace": "FiraCode Nerd Font",
"fontSize": 11,
"padding": "0, 0, 0, 0",
"useAcrylic": true,
"acrylicOpacity": 0.8,
"cursorShape": "emptyBox",
"antialiasingMode": "cleartype",
},
"list":
[
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "Windows PowerShell",
"commandline": "powershell.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profile.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "Command Prompt",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
{
"guid": "{a5a97cb8-8961-5535-816d-772efe0c6a3f}",
"hidden": false,
"name": "Arch",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "http://wsl$/Arch/home/kiven/",
"icon": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Archlinux-icon-crystal-64.svg/1200px-Archlinux-icon-crystal-64.svg.png"
},
{
"guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
"hidden": false,
"name": "Ubuntu-20.04",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "http://wsl$/Ubuntu-20.04/home/kiven/"
}
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [],
// Add custom actions and keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about actions and keybindings, visit https://aka.ms/terminal-keybindings
"actions":
[
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },
// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]
}
wsl2
wsl2 要求系統(tǒng)版本應(yīng)該在 win10, version 2004, build 19041 及以上。
首先需要開(kāi)啟 wsl丛塌,可通過(guò) 控制面板->程序->啟用或關(guān)閉 Windows 功能->勾選 適用于 Linux 的 Windows 子系統(tǒng) 和 虛擬機(jī)平臺(tái) 來(lái)開(kāi)啟,或者以管理員身份打開(kāi) powershell
畜疾,運(yùn)行如下命令來(lái)啟動(dòng)需要的組件
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
重啟之后赴邻,需要在 此處 下載并安裝適用于 x64 計(jì)算機(jī)的最新 wsl2 Linux 內(nèi)核更新包。
最后啡捶,打開(kāi) powershell姥敛,運(yùn)行如下命令,將 wsl 的默認(rèn)版本設(shè)置為 wsl2
wsl --set-default-version 2
簡(jiǎn)單來(lái)說(shuō)瞎暑,wsl 和 wsl2 的區(qū)別在于彤敛,wsl 是指令翻譯的形式來(lái)實(shí)現(xiàn) linux 功能与帆,而 wsl2 則是基于 hyper-v 虛擬技術(shù)。
Arch
Arch 對(duì)人的吸引力我就不贅述了墨榄。
安裝 arch wsl
在 yuk7/ArchWSL - Releases 中下載 Arch.zip
玄糟,根據(jù) yuk7/ArchWSL -Wiki 進(jìn)行安裝。
換源更新
進(jìn)入 arch wsl 中后袄秩,執(zhí)行以下命令(root 身份)
passwd # 設(shè)置 root 密碼
用 vim
或者 nano
打開(kāi) /etc/pacman.d/mirrorlist
阵翎,將 China
下面的源取消注釋。
執(zhí)行如下命令
# 初始化 keyring
pacman-key --init
pacman-key --populate
pacman -Syu
用 vim
打開(kāi) /etc/pacman.conf
之剧,取消 #Color
注釋?zhuān)谖募┪布由?/p>
[archlinuxcn]
Server = https://mirrors.aliyun.com/archlinuxcn/$arch
執(zhí)行如下命令
pacman -Syy
pacman -S archlinuxcn-keyring
創(chuàng)建用戶(hù)
一般使用普通用戶(hù)進(jìn)行操作郭卫,防止誤操作導(dǎo)致 linux 無(wú)法運(yùn)行。
# 新建用戶(hù)背稼,-m 為用戶(hù)創(chuàng)建家目錄贰军,-G wheel 將用戶(hù)添加到 wheel 用戶(hù)組
useradd -m -G wheel <youname>
# 設(shè)置密碼
passwd <youname>
編輯 /etc/sudoers
,將 # $wheel ALL=(ALL) ALL
的注釋去掉蟹肘,使得 wheel
組用戶(hù)能夠使用 root
權(quán)限词疼。
在 powershell 中進(jìn)入到 Arch.exe 所在文件夾,設(shè)置 wsl 默認(rèn)登陸用戶(hù)和默認(rèn)的 wsl
.\Arch.exe config --default-user <youname>
wsl -s Arch
安裝常用軟件
# 基本 linux 命令集
sudo pacman -S base-devel
# yay
sudo pacman -S yay
# yay 換源
yay --aururl "https://aur.tuna.tsinghua.edu.cn" --save
# 其它一些常用的指令
sudo pacman -S neofetch lolcat bat tree
# git openssh man-pages
sudo pacman -S git openssh man-pages
# 安裝 firacode 字體
sudo pacman -S nerd-fonts-fira-code
安裝 zsh
sudo pacman -S zsh
# 改變當(dāng)前用戶(hù)默認(rèn)的 shell
chsh -s /bin/zsh
# 使用 antigen 管理 zsh 插件
sudo yay -S antigen
在 .zshrc
中添加
# Start antigen
# Load antigen -- plugin manager
source /usr/share/zsh/share/antigen.zsh
# Load oh-my-zsh
antigen use oh-my-zsh
antigen bundle git
antigen bundle zsh-users/zsh-completions; rehash
antigen bundle pip
antigen bundle command-not-found
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-autosuggestions
# Antigen done
antigen apply
# End antigen
# 安裝 starship 美化命令行提示
sudo pacman -S starship
參考 starship疆前,在 .zshrc
中添加
eval "$(starship init zsh)"
執(zhí)行 exec $SHELL
即可看到更新的效果寒跳。
安裝 pyqt5 環(huán)境
sudo pacman -S python python-pip
sudo pacman -S pyenv
sudo pacman -S python-pipenv
sudo pacman -S pyqt5
sudo pacman -S qt5-tools
在 .zshrc
中添加
# set pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
安裝 node 開(kāi)發(fā)環(huán)境
sudo pacman -S nvm
在 .zshrc
中添加
source /usr/share/nvm/init-nvm.sh
# 安裝 node v10.15
nvm install v10.15.0
# 設(shè)置默認(rèn)版本
nvm use v10.15.0
# 安裝 yarn
sudo pacman -S yarn
# 安裝 nrm
npm install -g nrm
# 查看有哪些源
nrm ls
# 選擇 taobao 源
nrm usr taobao
啟用 X Server 圖形環(huán)境
win 安裝 VcXsrv
首先在 windows 上安裝 VcXsrv
找到軟件的安裝路徑,對(duì)兩個(gè)可執(zhí)行文件 vcxsrv.exe
和 xlaunch.exe
進(jìn)行操作:右擊->屬性->兼容性->更改高 DPI 設(shè)置->勾選替代高 DPI 縮放行為竹椒,目的是使得 VcXsrc 在高分辨率的顯示屏上具有清晰的顯示效果童太。
打開(kāi) xlaunch.exe
,一路默認(rèn)胸完,在 Extra settings
界面中书释,勾選 Disable acess control
,在 Additional parameters for VcXsrv
里填寫(xiě) -ac
赊窥,然后保存配置文件爆惧,然后就可以雙擊該文件直接啟動(dòng)或者移至 Startup
文件夾中開(kāi)機(jī)自啟。
配置 arch
# 首先需要安裝 xorg
sudo pacman -S xorg xorg-xinit
在 .zshrc
中添加
# wsl settings
export DISPLAY=`cat /etc/resolv.conf | grep nameserver | awk '{print $2}'`:0
export LIBGL_ALWAYS_INDIRECT=1
配置顯示輸出地址
編輯 /etc/X11/Xwrapper.config
锨能,修改或增加
allowed_users=anybody
然后就可以通過(guò) xeyes
命令來(lái)測(cè)試顯示是否正常了扯再。
問(wèn)題
大部分問(wèn)題都可以參考 Known issues 來(lái)解決。
對(duì)于有些 gui 是無(wú)法用 vcxsrv 的 multi window
的方式來(lái)呈現(xiàn)的址遇,例如 dwm
熄阻,這時(shí)候可以選擇 one large window
來(lái)顯示。
最后
到此倔约,基本環(huán)境已經(jīng)搭建完畢秃殉,可以很好地在 win 中使用 arch,同時(shí)還可以在 arch 中使用 win 中的命令,例如可以在任意位置 code .
打開(kāi) vscode钾军,還可以使用 explorer.exe .
打開(kāi) win 的資源管理器鳄袍,還可以在 win 中下載 docker desktop
,之后在 arch 中直接使用 docker
吏恭,十分方便拗小。