Installation
# Check your wsl version and set the default to wsl2 wsl --version wsl --set-default-version 2 # List available Linux distributions and install the selected one wsl --list --online wsl --install -d <Distribution Name> # List installed Linux distributions wsl --list --verbos
Set WSL version to 1 or 2
To designate the version of WSL (1 or 2) that a Linux distribution is running on:
wsl --set-version <DistributionName> 2
Switching between WSL 1 and WSL 2 can be time-consuming and result in failures due to the differences between the two architectures.
For distributions with large projects, we recommend backing up files before attempting a conversion.
Reset WSL password
# wsl -d <your-distro-name> -u root wsl --user root # Reset the password of root passwd root # Reset the password of user passwd <username>
Shutdown
Immediately terminates all running distributions and the WSL 2 lightweight utility virtual machine.
wsl --shutdown
This command may be necessary in instances that require you to restart the WSL 2 virtual machine environment, such as changing memory usage limits or making a change to your .wslconfig file.
Terminate
To terminate the specified distribution, or stop it from running, replace <Distribution Name>
with the name of the targeted distribution.
wsl --terminate <Distribution Name>
Identify IP address
-
wsl hostname -I
: Returns the IP address of your Linux distribution installed via WSL 2 (the WSL 2 VM address) -
ip route show | grep -i default | awk '{ print $3}'
: Returns the IP address of the Windows machine as seen from WSL 2 (the WSL 2 VM)
Unregister or uninstall a Linux distribution
While Linux distributions can be installed through the Microsoft Store, they can't be uninstalled through the store.
Replacing <DistributionName>
with the name of your targeted Linux distribution will unregister that distribution from WSL so it can be reinstalled or cleaned up:
wsl --unregister <DistributionName>
Once unregistered, all data, settings, and software associated with that distribution will be permanently lost. Reinstalling from the store will install a clean copy of the distribution. For example, wsl --unregister Ubuntu
would remove Ubuntu from the distributions available in WSL. Running wsl --list
will reveal that it is no longer listed.
You can also uninstall the Linux distribution app on your Windows machine just like any other store application. To reinstall, find the distribution in the Microsoft Store and select "Launch".
Snapshot and rollback
-
Check the VM status
wsl -l -v
-
Select the machine on which you want to take the snapshot:
wsl --export <Distribution Name> <FileName> #wsl --export Debian d:\wsl-debian.tar
-
If you want to roll back:
wsl --import <Distribution Name> <InstallLocation> <FileName>
for example,
wsl --unregister Debian # wsl is installed on C: by default, you can change the install loctation wsl --import Debian d:\wsl d:\wsl-debian.tar --version 2 Debian config --default-user [USERNAME] rm d:\wsl-debian.tar