If WSL is using too much disk space, behaving incorrectly, or holding files you no longer need, you may be wondering how to clear WSL. The right method depends on what you want to clear: temporary files inside Linux, a running WSL session, cached package downloads, or an entire Linux distribution. Some options are safe and reversible; others permanently delete your Linux files.
This guide explains how to clear WSL on Windows 10 and Windows 11, including how to stop WSL, remove Linux caches, free up disk space, reset a distribution, and completely uninstall a distro. Before using any command that removes a distribution, back up anything important.
What Does “Clear WSL” Mean?
WSL, or Windows Subsystem for Linux, lets you run Linux distributions such as Ubuntu, Debian, and Kali on Windows. It stores each distribution’s Linux filesystem separately. That means clearing WSL can refer to several different tasks:
- Stop WSL: Close active Linux sessions without deleting files.
- Clear Linux caches: Remove temporary files or downloaded package archives.
- Free Windows disk space: Remove unused files and, when appropriate, compact WSL’s virtual disk.
- Reset a distribution: Return one Linux distro to a fresh state by deleting its data.
- Uninstall WSL: Remove distributions or disable the Windows feature itself.
Choose the least destructive option that meets your needs. If you only want WSL to stop running, do not unregister your distribution. If you want to start fresh, make sure you understand that resetting or unregistering can erase your Linux files.
How to Stop or Restart WSL Safely
To stop all running WSL distributions and their associated WSL 2 virtual machine, open PowerShell or Windows Terminal and run:
wsl --shutdown
This shuts down WSL but does not delete your Linux files, settings, or installed applications. Run it when WSL is unresponsive, after changing certain WSL settings, or before trying to compact a virtual disk.
To stop just one distribution, first view the installed distributions:
wsl --list --running
Then terminate the specific distro, replacing Ubuntu with its exact name:
wsl --terminate Ubuntu
You can launch it again from the Start menu or with wsl -d Ubuntu. If a distro is still listed as running after you close its terminal, that is normal: WSL may keep it active in the background. Use wsl --shutdown when you want to stop everything.
How to Clear Linux Package and Temporary Caches
Removing unneeded files inside Linux is often the best first step when a WSL distribution is using extra space. Open the distro’s terminal and use commands for its Linux distribution. For Ubuntu or Debian, update the package information and remove downloaded package archives with:
sudo apt clean
To remove package files that are no longer needed, run:
sudo apt autoremove
Review the packages shown before confirming. You can also clear older system journal entries on distributions that use systemd:
sudo journalctl --vacuum-time=7d
This keeps only the most recent seven days of journal logs. The exact behavior depends on whether systemd is enabled and how your distro is configured. To identify large directories before deleting anything, try:
du -h --max-depth=1 ~ 2>/dev/null | sort -h
This checks folders in your Linux home directory. Inspect results carefully: deleting files from a project, application, or configuration folder may break your work. Avoid deleting unfamiliar system directories just to reduce disk usage.
For other package managers, use their own cleanup commands. For example, Fedora-based distributions use DNF, while Alpine uses APK. Do not run Ubuntu or Debian package commands in a distro that uses a different package manager.
How to Reset a WSL Distribution
If a distro is corrupted or you want a completely clean Linux environment, you can reset it. A reset removes that distribution’s installed packages, Linux user accounts, settings, and files. It does not normally remove other WSL distributions, but it is still destructive.
First, back up important files. You can copy them to a Windows folder accessible from Linux under /mnt/c, or export the whole distribution to a tar archive from PowerShell:
wsl --export Ubuntu C:\Backups\ubuntu-backup.tar
Change the distro name and backup path to match your setup. Ensure the destination folder exists and has enough free space. Once you have verified your backup, remove the distro registration with:
wsl --unregister Ubuntu
Warning: wsl --unregister permanently deletes the specified distribution’s WSL filesystem. It is not the same as shutting down WSL, and the deletion is not undone by reinstalling Ubuntu. Confirm the exact distro name before running the command.
To see the names available on your computer, run:
wsl --list --verbose
After unregistering the distro, install it again from the Microsoft Store or with the appropriate wsl --install command. On first launch, you will create a new Linux user. To restore a distribution from a backup, you can import it using wsl --import; check wsl --help for the options supported by your WSL version.
Reset a Distro Through Windows Settings
Some Linux distributions installed from the Microsoft Store offer a Reset option in Windows Settings. Open Settings > Apps > Installed apps (or Apps & features on some Windows versions), select the distro, and open its advanced options. If a Reset button is available, Windows will warn you that the app’s data will be deleted.
The wording and available options can differ by Windows version and distro. Treat Reset as a data-erasing operation, not as a way to restart WSL. Back up your Linux files first. If the distro does not provide this option, use the export-and-unregister method instead.
How to Free Disk Space Used by WSL
Deleting files inside Linux may not immediately reduce the size of the WSL 2 virtual disk file shown in Windows. WSL 2 stores Linux data in a virtual hard disk, commonly named ext4.vhdx. The file can remain large even after you remove files inside the distro because the virtual disk may not automatically shrink.
Start by clearing unnecessary Linux files as described above. If your distro supports it, you can then run a trim operation from its terminal:
sudo fstrim -av
Next, close Linux applications and shut down WSL from PowerShell:
wsl --shutdown
Depending on your Windows version and setup, additional steps may be required to compact the virtual disk. One option for eligible systems is the Windows diskpart utility. Open PowerShell or Command Prompt as an administrator, start DiskPart, select the correct WSL virtual disk file, and compact it:
diskpart
select vdisk file="C:\path\to\ext4.vhdx"
compact vdisk
exit
Replace the example path with the actual path to your distro’s VHDX file. The file is often stored in a package folder under your Windows user profile, but its location varies depending on how the distro was installed. Do not guess the path or select a disk belonging to another application. If DiskPart reports that the disk is in use or cannot be compacted, stop and check the requirements for your Windows version rather than forcing the operation.
Compacting can take time and may not return all space you expected. For a safer, simpler approach when the VHDX is exceptionally large, export the distro, unregister it, and import it again into a new location. This also requires a verified backup and care: unregistering deletes the original distro data.
How to Remove a WSL Distribution
If you no longer need one Linux distro, you can remove just that distro without uninstalling WSL entirely. Find its exact registered name with:
wsl --list --verbose
Then, after backing up anything you need, run:
wsl --unregister Debian
Replace Debian with the name shown on your system. This removes the distribution and its filesystem. Repeat only for other distros you intentionally want to delete. Removing one distribution does not automatically erase files stored in a different distro or ordinary Windows folders.
How to Uninstall WSL Completely
Uninstalling WSL is different from clearing a distro. First, decide whether you want to keep any Linux distributions. Export or copy their files before removing them. You can uninstall a Store-installed distro from Settings > Apps > Installed apps, but verify whether its data will also be removed.
To disable the Windows components, open an administrator PowerShell window and use the Windows Features interface, or follow Microsoft’s current instructions for your Windows version. Feature names and uninstall steps can vary, particularly between older WSL installations and newer WSL packages. Removing WSL components does not replace backing up your data, and uninstalling WSL is unnecessary if your goal is only to clear a cache or stop a running session.
Common WSL Cleanup Mistakes to Avoid
-
Confusing shutdown with deletion:
wsl --shutdownstops WSL;wsl --unregisterdeletes a distro. - Assuming deleted Linux files instantly shrink the VHDX: Virtual disk space may need to be trimmed and compacted.
-
Using the wrong distro name: Copy the exact name from
wsl --list --verbose. - Skipping a backup: Export important data before resetting, unregistering, or reinstalling.
- Deleting files without checking them: Use disk-usage tools to investigate before removing unfamiliar folders.
Frequently Asked Questions About Clearing WSL
Does wsl --shutdown delete my Linux files? No. It stops running WSL instances but keeps your distributions and their data.
How do I clear WSL without uninstalling Ubuntu? Clean package caches and temporary files inside Ubuntu, then shut WSL down. Avoid wsl --unregister unless you want to delete the distribution.
Why is my WSL disk still large after deleting files? The WSL 2 virtual disk may not automatically shrink when Linux files are removed. Trim and compact the VHDX using a method supported by your Windows setup.
Can I recover a distro after unregistering it? Unregistering is intended to delete its data. Recovery is not guaranteed, so export the distro or back up files before running the command.
Conclusion
To clear WSL, first decide whether you want to stop it, clean Linux files, reclaim Windows disk space, or reset a distribution. Use wsl --shutdown for a safe stop, package-manager cleanup commands for caches, and disk compaction when a WSL 2 virtual disk remains large. Use wsl --unregister only when you are ready to permanently remove a distro. Backing up your Linux data before any reset or removal is the most important step.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.