在 Windows 中配置 WSL2 与 Debian 的全流程

简介: 【8月更文挑战第27天】本文详细介绍了在Windows环境中配置WSL2与Debian的全过程,包括确认Windows版本、启用相关功能、安装WSL并设置版本为WSL2、下载安装Debian、配置国内镜像源,以及设置Xserver实现GUI功能。通过这些步骤,用户能够顺利完成配置,并进行基本优化。

以下是在 Windows 中配置 WSL2 与 Debian 的全流程:


一、确认 Windows 版本


确保 Windows 版本为 Windows 10 版本大于等于 2004(内部版本大于等于 19041)或 Windows 11 1。以管理员运行 PowerShell,输入 (system.environment)::osversion.version 来查看版本信息 1


二、开启相关 Windows 功能


开启 Windows Subsystem for Linux 和 Virtual Machine Platform。以管理员身份运行 PowerShell,输入以下命令并重启 Windows 1


Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform


三、安装 WSL 并设置版本


  1. 以管理员运行 PowerShell,输入以下指令安装 WSL1
  • wsl --install :安装 WSL,根据微软文档,某些版本下默认会安装 Ubuntu。
  • wsl --install --no-distribution :只安装 WSL 而不安装特定的 Linux 发行版。
  1. 安装完成后设置 WSL 版本为 WSL21
  • wsl --set-default-version 2
  1. 输入 wsl --version 确认 WSL 版本 1


四、下载并安装 Debian


  1. 打开 Microsoft Store 1
  2. 在 Microsoft Store 中搜索并安装 Debian 1
  3. 安装完成后打开 Debian,第一次进入会要求设置用户名和密码 1


五、配置国内镜像源(以清华镜像源为例)


  1. 打开并登录 WSL - Debian 1
  2. 将原有/etc/apt/sources.list文件设置备份1
  • sudo mv ~/etc/apt/sources.list ~/etc/apt/sources.list.backup
  1. 创建新的/etc/apt/sources.list文件1
  • sudo touch ~/etc/apt/sources.list
  1. 在新的 sources.list 中输入以下内容 1


deb http://mirrors.tuna.tsinghua.edu.cn/debian/bookworm main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/bookworm main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/bookworm-updates main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/bookworm-updates main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian/bookworm-backports main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/bookworm-backports main contrib non-free non-free-firmware
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security/bookworm-security main contrib non-free non-free-firmware
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security/bookworm-security main contrib non-free non-free-firmware


  1. 在 Debian CLI 中输入以下代码更新 Debian 软件并安装镜像站 HTTPS 证书1
  • sudo apt update -y && sudo apt upgrade -y
  • sudo apt install apt-transport-https ca-certificates
  1. ~/etc/apt/sources.list 中,将所有的 http:// 改成 https:// 1


六、配置 GUI(以使用 Xserver 为例)


  1. 在 sourceforge 上下载 vcxsrv windows xserver 1
  2. 安装 vcxsrv 并运行 xlaunch 1
  3. 在 xlaunch 的 Select Display Settings 中,将 Display Number 改为 0 1
  4. 在 xlaunch 的 Extra Settings 中,勾选 Disable Access Control 选项 1


完成以上步骤,就完成了在 Windows 中配置 WSL2 与 Debian,并进行了一些基本的优化配置。如果需要进一步配置中文字体与输入法等,可以参考相关的文档和教程进行操作 1

相关文章
|
20天前
|
Java 应用服务中间件 开发工具
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
[App Service for Windows]通过 KUDU 查看 Tomcat 配置信息
|
20天前
|
Java 应用服务中间件 Windows
【App Service for Windows】为 App Service 配置自定义 Tomcat 环境
【App Service for Windows】为 App Service 配置自定义 Tomcat 环境
|
30天前
|
安全 机器人 程序员
Windows 计划任务每天隔 3 小时运行一次批处理文件详细配置步骤
Windows 计划任务每天隔 3 小时运行一次批处理文件详细配置步骤
|
16天前
|
网络安全 Windows
在Windows电脑上启动并配置SSH服务
在Windows电脑上启动并配置SSH服务
38 0
|
16天前
|
Ubuntu Linux 开发工具
Windows11 WSL2 Ubuntu编译安装perf工具
Windows11 WSL2 Ubuntu编译安装perf工具
33 0
|
21天前
【Azure 应用服务】App Service 配置 Application Settings 访问Storage Account得到 could not be resolved: '*.file.core.windows.net'的报错。没有解析成对应中国区 Storage Account地址 *.file.core.chinacloudapi.cn
【Azure 应用服务】App Service 配置 Application Settings 访问Storage Account得到 could not be resolved: '*.file.core.windows.net'的报错。没有解析成对应中国区 Storage Account地址 *.file.core.chinacloudapi.cn
|
22天前
|
JavaScript Java Python
【Azure 应用服务】在Azure App Service for Windows 中部署Java/NodeJS/Python项目时,web.config的配置模板内容
【Azure 应用服务】在Azure App Service for Windows 中部署Java/NodeJS/Python项目时,web.config的配置模板内容
|
30天前
|
JavaScript Windows
记一下 Windows11 安装与配置 node.js 的标准步骤
这篇文章记录了在Windows 11系统上安装和配置Node.js的步骤,包括安装Node.js、验证安装、配置npm、设置npm镜像加速、全局安装cnpm并配置镜像、解决TLS连接不安全警告的详细过程。
58 0
|
1月前
|
存储 Windows
Windows 下 WSL2 安装 ROS2 Iron 和 GAZEBO
Windows 下 WSL2 安装 ROS2 Iron 和 GAZEBO
36 0
|
10天前
|
网络安全 虚拟化 Windows
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题
windows 11安装openSSH server 遇到的"kex_exchange_identification: read: Connection reset"问题