WSL 环境配置
目录
记录 WSL 环境的配置过程。
1 安装 WSL
-
打开
启用或关闭 Windows 功能,勾选适用于 Linux 的 Windows 子系统、虚拟机平台和Hyper-V,点击确定并重启电脑。 -
打开 PowerShell (管理员权限),执行以下命令安装 WSL 和 Debian 发行版:
wsl --update wsl --set-default-version 2 wsl --install -d Debian -
配置 Debian 用户名和密码。
2 移动 WSL 虚拟磁盘位置
-
关闭 WSL:
wsl --shutdown -
直接移动:
wsl --manage Debian --move <新路径>
3 初始化 WSL
-
更新软件包列表并升级已安装的软件包:
sudo apt update && sudo apt upgrade -y -
美化终端:
sudo apt install -y zsh git wget sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)" 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修改
~/.zshrc,添加插件:plugins=(git zsh-autosuggestions zsh-syntax-highlighting)重启终端或执行
source ~/.zshrc。
4 汉化
-
修改系统语言为中文:
sudo apt install locales sudo dpkg-reconfigure locales按向下键选择
zh_CN.UTF-8,按空格键选中,回车确认;选择zh_CN.UTF-8作为默认语言,回车确认。 -
安装中文字体:
sudo apt install -y fonts-wqy-zenhei fonts-wqy-microhei
5 安装桌面环境
-
安装 XFCE4 桌面环境:
sudo apt install -y xfce4注意执行上述命令后,仅支持窗口级 GUI,不支持完整桌面环境。
6 与 VS Code 集成
-
安装 VS Code,并安装
WSL插件。 -
在 WSL 终端中:
code .
7 压缩 WSL 虚拟磁盘
-
关闭 WSL:
wsl --shutdown -
执行:
diskpart -
在 diskpart 提示符下,执行以下命令:
select vdisk file=<WSL 虚拟磁盘路径> compact vdisk
8 其他
8.1 安装 .NET SDK
-
添加环境变量:
nano ~/.zshrc在其中添加:
export DOTNET_CLI_TELEMETRY_OPTOUT=1 -
https://learn.microsoft.com/zh-cn/dotnet/core/install/linux-debian