目录
1. List Installed WSL Distributions
2. Set Default Distribution and WSL Version
Set a default Linux distribution
Change WSL version for a distribution
3. Install a New Distribution
Install from command line:
4. Remove or Uninstall a Distribution
5. Start, Shut Down, or Terminate Distributions
Start a specific distribution:
Shut down a running distribution:
Shut down all running distributions:
6. Import and Export Distributions (Backup & Migrate)
Export a distribution:
Import a new distribution from a tar file:
7. Set Default User in a Distribution
8. Manage Kernel and Updates
Final Tips
首页 系统教程 Windows系列 如何管理Linux(WSL)发行版Windows子系统

如何管理Linux(WSL)发行版Windows子系统

Aug 08, 2025 pm 01:30 PM
linux wsl

使用wsl -l -v列出已安装的发行版及其状态;2. 用wsl --set-default设置默认发行版,wsl --set-version切换WSL版本;3. 通过wsl --install -d安装新发行版;4. 使用wsl --unregister卸载发行版并删除所有数据;5. 用wsl -d启动、wsl --terminate停止特定发行版,wsl --shutdown关闭所有实例;6. 使用wsl --export导出和wsl --import导入发行版以实现备份或迁移;7. 通过配置/etc/wsl.conf设置默认用户;8. 运行wsl --update更新内核,必要时回滚或调整自动更新设置,建议始终使用WSL 2并将发行版存储在SSD上以获得最佳性能。

How to manage Windows Subsystem for Linux (WSL) distributions

Managing Windows Subsystem for Linux (WSL) distributions is straightforward once you know the right commands and tools. Whether you're installing, removing, switching between versions, or troubleshooting, here’s what you need to know.

How to manage Windows Subsystem for Linux (WSL) distributions

1. List Installed WSL Distributions

To see which Linux distributions you’ve installed and their status:

wsl --list --verbose

or shorthand:

How to manage Windows Subsystem for Linux (WSL) distributions
wsl -l -v

This shows:

  • Distribution name
  • WSL version (1 or 2)
  • Current state (Running / Stopped)

2. Set Default Distribution and WSL Version

Set a default Linux distribution

When you run wsl, it launches the default distro. To change it:

How to manage Windows Subsystem for Linux (WSL) distributions
wsl --set-default <DistributionName>

Example:

wsl --set-default Ubuntu-22.04

Change WSL version for a distribution

You can switch between WSL 1 and WSL 2 (WSL 2 is recommended for better performance and full system call compatibility).

Check your current version:

wsl -l -v

Upgrade to WSL 2:

wsl --set-version <DistributionName> 2

Downgrade to WSL 1 (if needed):

wsl --set-version <DistributionName> 1

⚠️ Note: Downgrading may take time and isn't always recommended. WSL 2 is faster and more compatible.


3. Install a New Distribution

You can install Linux distros from the Microsoft Store (e.g., Ubuntu, Debian, Kali, Alpine), or manually via command line.

Install from command line:

wsl --install -d <DistributionName>

Example:

wsl --install -d Ubuntu

To see all available distributions:

wsl --list --online

Or:

wsl --show-distributions

4. Remove or Uninstall a Distribution

If you no longer need a Linux distribution:

wsl --unregister <DistributionName>

Example:

wsl --unregister Debian

This removes the distribution, all its files, settings, and user data. Be careful—this cannot be undone.


5. Start, Shut Down, or Terminate Distributions

Start a specific distribution:

wsl --distribution <DistributionName>

or:

wsl -d <DistributionName>

Shut down a running distribution:

wsl --terminate <DistributionName>

This stops the instance. It will restart cleanly next time.

Shut down all running distributions:

wsl --shutdown

Useful when troubleshooting network issues or file locks.


6. Import and Export Distributions (Backup & Migrate)

You can export a distribution to a tar file (great for backup), then import it later or on another machine.

Export a distribution:

wsl --export <DistributionName> <FileName>.tar

Example:

wsl --export Ubuntu backup-ubuntu.tar

Import a new distribution from a tar file:

wsl --import <NewName> <InstallPath> <BackupFile.tar> --version 2

Example:

wsl --import MyUbuntu D:\wsl\MyUbuntu backup-ubuntu.tar --version 2

Note: After import, the default user is root. To set a default user, you’ll need to configure /etc/wsl.conf or use a launcher app.


7. Set Default User in a Distribution

After importing or installing, you might end up as root. To set your regular user as default:

  1. Launch the distro:

    wsl -d <DistributionName>
  2. Create or edit /etc/wsl.conf:

    [user]
    default = yourusername
  3. Exit and terminate:

    wsl --terminate <DistributionName>

Next time you start it, you’ll log in as that user.


8. Manage Kernel and Updates

  • Update WSL kernel: Run in PowerShell (as admin):

    wsl --update
  • Rollback (if update causes issues):

    wsl --update --rollback
  • Set update policy:

    wsl --set-update-settings --auto-update Disabled

    (or Enabled, Defer)


    Final Tips

    • Always use WSL 2 unless you have a specific reason not to.
    • Use wsl --shutdown before hibernating or troubleshooting.
    • Back up important distros using --export before unregistering.
    • Store distributions on an SSD for better performance.

    Basically, with wsl --list, --set-default, --unregister, and --export/import, you’ve got full control over your Linux environments on Windows.

    以上是如何管理Linux(WSL)发行版Windows子系统的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Stock Market GPT

Stock Market GPT

人工智能驱动投资研究,做出更明智的决策

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

爱思助手正版下载入口_爱思助手iPhone安装链接 爱思助手正版下载入口_爱思助手iPhone安装链接 Sep 16, 2025 am 11:30 AM

爱思助手正版下载入口在官网https://www.i4.cn/,提供电脑端和手机端下载,支持设备管理、应用安装、模式切换、屏幕投射及文件管理等功能。

华为HarmonyOS 6系统取消'NEXT”后缀:以后都是原生鸿蒙 华为HarmonyOS 6系统取消'NEXT”后缀:以后都是原生鸿蒙 Sep 24, 2025 pm 04:12 PM

9月18日最新消息,华为HarmonyOS6已启动多轮面向开发者的预览版推送,近期更首次向部分尝鲜用户开放体验资格。根据用户反馈,当前系统名称已不再显示“NEXT”后缀,正式更名为HarmonyOS6.0。华为最初于2023年8月的开发者大会首次提出HarmonyOSNEXT这一命名,旨在标志鸿蒙系统迈入全新发展阶段,实现真正的原生自研。HarmonyOSNEXT最核心的突破在于彻底采用自主研发的系统底层架构,全面移除Linux内核及安卓AOSP代码,仅运行基于HarmonyOS内核的应用程序,

如何在Linux上运行Windows程序 如何在Linux上运行Windows程序 Sep 18, 2025 am 03:25 AM

torunwindowsProgramsonLinux,TrytheSemethods:1。usesewinetodirectlyrun.exefiles.2.installplayonlinuxforeasierwinemanagement.3.setupawindowsvirtualmachinewithvirtualbox.4.uselututristointristristoinstallandrundrundrunwindrundrunwindrunwindrunwindrundrunwindremeseameameameameamemellysly。

如何在Linux中找到程序的路径 如何在Linux中找到程序的路径 Sep 16, 2025 am 08:56 AM

tolocateaprogram'sinstallationPathOnlinux,使用:1。WHAICHPROGRAME_NAMEFORQUICKPATS基础lookup.2.Whereisprogram_nametofingrogram_nametofindbinaries,manpages.3.locateWithupDateWithupDatedBandGrepforfastFastFastFastFastFastFastFastFastFastilesearches.4.4.find/typef-typef-typef-typef-ecececutable-name-name progry'progry'progry'fort

如何在Linux中管理启动程序 如何在Linux中管理启动程序 Sep 09, 2025 am 05:30 AM

UseGUItoolslikeStartupApplicationsinGNOME,AutostartinKDE,orSessionandStartupinXfcetomanageloginprograms.2.Manuallyaddstartupentriesvia.desktopfilesin~/.config/autostart/followingXDGstandards.3.Forsystem-levelservices,usesystemctlenable/disabletocontr

如何在Linux上拍摄屏幕截图 如何在Linux上拍摄屏幕截图 Sep 15, 2025 am 03:35 AM

TotakesCreenshotsonLinux:1。useprtscnkeyforfullscreen,alt prtscnforactiveWindow.2.UseGnomesCreensHottoolShottoolFormoreOptions.3.UseGeSnome-ScreenshotCommandInterminal.4.InstallandSallandSallansCrotforlightweightlightweightweightlightweightweightlightweightlightweightCommand-command-command-lineCapturing。

如何在Linux上安装VS代码 如何在Linux上安装VS代码 Sep 16, 2025 am 09:04 AM

toinstallvScodeonLinux,Usetheeficialaptrepositoryforautomationupdates,SnapforCross-Distribution-Compatibility,Oramanualtarballforfullcontrol.ChooseBashioneBasedonyourSasedonyourSasedonyoursyStemsteneds和Needs。

如何在Linux命令行中检查磁盘空间 如何在Linux命令行中检查磁盘空间 Sep 21, 2025 am 04:46 AM

ToCheckDiskSpaceOnlinux,Usedf-HforanoverViewOfStorage,Du-ShtofIndDirectorySizes,lsblktolistblockdevices,OrinstallncduforanInteractiveanalysission.thesetoolsetoolshelpmonitor和manageSkusageSkusageSkusageSkusageageSageSkusageSageSkageAgefly。

See all articles