Windows WSL2安装Ubuntu24.04全攻略

一、WSL Ubuntu安装步骤详解

教程所需文件下载:http://yun.pkp123.cn:886/share.php?code=VdlOaD09

  1. 打开管理员PowerShell
  • 右键点击「开始菜单」

  • 选择「Windows PowerShell (管理员)」

  1. 运行启用命令

复制粘贴以下命令并按Enter执行:

bash 复制代码
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
   
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

执行完命令后,重启电脑以应用更改

: 安装WSL 2内核
  1. 重新打开管理员PowerShell

下载WSL 2内核更新包

bash 复制代码
Invoke-WebRequest-Uri https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi-OutFile C:\wsl_update_x64.msi

嫌下载太慢麻烦可以使用我打包好的

  1. 安装内核更新
bash 复制代码
msiexec.exe /i C:\wsl_update_x64.msi /quiet
  1. 设置WSL 2为默认版本
bash 复制代码
wsl --set-default-version 2
三、获取Ubuntu WSL镜像
  1. 下载Ubuntu 24.04镜像
  • 使用浏览器访问官方下载地址:`https://aka.ms/wslubuntu2404\`

  • 等待下载完成

  • 将文件保存到C盘根目录:`C:\ubuntu-24.04.4-wsl-amd64.gz`

  • 从ubtuntu官网下载会比较慢、可以使用清华大学的源下载:https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/noble/

  • 也可以直接使用我们打包好的、打包好的是ubtuntu24.04 需要其他镜像的可以去清华大学的镜像站自己下载别的版本。

四、 导入Ubuntu到WSL
  1. 创建WSL安装目录
bash 复制代码
New-Item -Path "C:\WSL\Ubuntu2404" -ItemType Directory -Force
  1. 导入Ubuntu镜像
bash 复制代码
wsl --import Ubuntu2404 "C:\WSL\Ubuntu2404" "C:\ubuntu-24.04.4-wsl-amd64.gz" --version 2
  1. 验证导入成功
bash 复制代码
wsl --list --all --verbose

应该能看到类似输出:

NAME STATE VERSION

Ubuntu2404 Stopped 2

导入成功后会有个磁盘映像文件

Linux里也会显示我们安装的版本

五、 配置用户和权限
  1. 创建普通用户
bash 复制代码
wsl -d Ubuntu2404 -u root -e "useradd -m -s /bin/bash ubuntu"
  1. 添加用户到sudo组
bash 复制代码
wsl -d Ubuntu2404 -u root -e "usermod -aG sudo ubuntu"

3.设置默认登录用户

bash 复制代码
wsl -d Ubuntu2404 -u root -e "echo [user] > /etc/wsl.conf"

wsl -d Ubuntu2404 -u root -e "echo default=ubuntu >> /etc/wsl.conf"
  1. 设置root密码
bash 复制代码
wsl -d Ubuntu2404 -u root -e bash -c "echo 'root:填自己需要的设置密码' | chpasswd"
6、使用指南

验证安装完成

bash 复制代码
Bash

查看当前用户

bash 复制代码
whoami

使用命令

启动Ubuntu

bash 复制代码
wsl -d Ubuntu2404

以root用户启动

bash 复制代码
wsl -d Ubuntu2404 -u root

更新系统

bash 复制代码
sudo apt update && sudo apt upgrade -y

管理命令

列出所有WSL实例

bash 复制代码
wsl --list --all --verbose

停止WSL实例

bash 复制代码
wsl --terminate Ubuntu2404

重启WSL服务

bash 复制代码
wsl --shutdown
相关推荐
七歌杜金房6 小时前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia1 天前
linux curl命令详解_curl详解
linux
扛枪的书生1 天前
Linux 网络管理器用法速查
linux
顺风尿一寸2 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode2 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫2 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux
AlfredZhao4 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
戴为沐5 天前
Linux内存扩容指南
linux
zylyehuo5 天前
Linux 彻底且安全地删除文件
linux
用户805533698036 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式