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
相关推荐
NamoAmitabha12820 小时前
libpng12-0 1.2.54-1ubuntu1.1 (amd64 binary) in ubuntu xenial
linux·ubuntu20.4
Madison-No721 小时前
搭建项目测试环境
linux·运维·服务器·python
吴声子夜歌1 天前
Shell编程实例——编写安全的shell脚本(二)
linux·运维·shell
xiaoye-duck1 天前
《Linux 网络编程》深入理解 IP 协议(二):网段划分、私有 IP 与 NAT 地址转换
linux·网络·ip
zx_741484811 天前
【Linux入门】Shell 函数、正则表达式与文本处理:cut 与 awk
linux·运维·正则表达式
Zenova EdgeOS1 天前
Linux dmesg 工业边缘实战:内核日志过滤、持久化与故障定位
linux·运维·边缘计算·工业边缘·dmesg·内核日志
金士顿1 天前
System.Text.Json Source Generator 深度解析:为什么 Native AOT 不喜欢反射
linux·asp.net core·arm64·net·native aot
做运维的阿瑞1 天前
Python 标准库汇总:分类速览与常用模块清单
linux·运维·python
kakakahahahaha1 天前
Windows Steam 游戏存档在哪里?定位和恢复排查流程
windows·其他·电脑·笔记本电脑·内容运营·软件需求
Xy-unu1 天前
Windows 开启外接显示器 HDR 后外接显示器无信号、无法扩展模式故障记录
windows