Windows Subsystem for Linux (WSL) 🪟
“适用于 Linux 的 Windows 子系统 (WSL) 可让开发人员直接在 Windows 上按原样运行 GNU/Linux 环境,且不会产生传统虚拟机或双启动设置的开销。”
参考资料
配置终端
安装 nerd-fonts
安装 Terminal + PowerShell
添加 Terminal-Icons
安装 Oh My Posh
安装 Scoop A command-line installer for Windows.
1 2 3 4 5 6 7 8 9 10 11 12 13 winget install JanDeDobbeleer.OhMyPosh notepad $PROFILE iwr -useb get.scoop.sh | iex scoop install aria2 scoop install neofetch
powerShell 支持多个配置文件并按照优先级加载。下面按照优先级顺序列出 Windows 下 PowerShell 配置文件的路径
所有用户、所有主机 $PSHOME\Profile.ps1
所有用户,当前主机 $PSHOME\Microsoft.PowerShell_profile.ps1
当前用户、所有主机 $Home\Documents\PowerShell\Profile.ps1
当前用户,当前主机 $Home\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
安装 WSL 开启功能
安装 Linux
1 2 3 4 5 6 7 8 9 10 11 12 wsl --install -d Ubuntu Installing, this may take a few minutes... WslRegisterDistribution failed with error: 0x8004032d Error: 0x8004032d (null) Press any key to continue ... wsl --list --verbose
配置
1 2 3 4 5 6 7 8 9 10 11 vim ~\.wslconfig [experimental ] autoMemoryReclaim=gradual networkingMode=mirrored dnsTunneling=true firewall=true autoProxy=true wsl --shutdown
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 sudo vim /etc/apt/sources.listsudo apt update && sudo apt upgradesudo apt install zsh curl -ysh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) " git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-syntax-highlighting vim ~/.zshrc plugins=( git zsh-autosuggestions zsh-syntax-highlighting ) source ~/.zshrcchsh -s `which zsh` nvim ~/.config/nvim/init.vim sudo apt install openssh-serversudo service ssh startsudo apt install net-toolsifconfig
迁移 WSL 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 hcjjj@laptop ~ wsl --shutdown hcjjj@laptop ~ wsl -l -v NAME STATE VERSION * Ubuntu Stopped 2 docker-desktop Stopped 2 hcjjj@laptop ~ wsl --export Ubuntu D:\WSL\ubuntu24 正在导出,这可能需要几分钟时间。 操作成功完成。 hcjjj@laptop ~ wsl --unregister Ubuntu 正在注销。 操作成功完成。 hcjjj@laptop ~ cd D:\WSL hcjjj@laptop ~ ls Directory: D:\WSL Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 2024 /11 /12 21 :28 Ubuntu -a--- 2024 /11 /12 21 :20 2056519680 ubuntu24hcjjj@laptop ~ wsl --import ubuntu D:\WSL\Ubuntu .\ubuntu24 正在导入,这可能需要几分钟时间。 操作成功完成。 hcjjj@laptop ~ wsl -d ubuntu