Essential WSL Commands
You can manage the WSL distros effectively using these commands.
These are some essential WSL commands that you should be aware of.
wsl
, used throughout this article, is also available from inside a WSL distribution. In order to access inside a Linux distribution, you need to use wsl.exe
instead of wsl
.List available WSL distributions
There are several distributions, that you can install directly from either Microsoft store or through terminal commands. When it comes to listing these distributions, it is easier to use the terminal commands.
Open a terminal in Windows and run:
wsl --list --online
Install Ubuntu, the default distribution
As specified in the above listing command, there are various distributions available, like Ubuntu and several versions of it, Debian, openSUSE, etc. But in WSL, Ubuntu is set as the default distribution, if you didn't tweak that explicitly.
So, if you want to install Ubuntu, you can open a terminal in Admin mode and run the command:
wsl --install
Install Debian or some other distribution
Not a fan of Ubuntu? Don't worry! You can install the other distributions, that are available by using the command:
wsl --install --distribution <distribution_name>
OR
wsl --install -d <distribution_name>
You should make sure that, the distribution_name
should be same as the name shown in the output of the wsl --list --online
command.
List installed distributions
If you have multiple distributions installed, it is important to list those for future management. In order to do that, use the command:
wsl --list --verbose
OR
wsl -l -v
As you can see, this will give the proper name of the installed distributions, including its current status (running or stopped) and the WSL version it is using.
Run a distribution from Windows terminal
If you have installed the distribution from the store, you can launch it from the start menu. But that's not always the case. Sometimes, you may need to rely on the terminal to run a distribution.
In that case, you can run a distribution by using:
wsl -d <distribution_name>
distribution_name
is the one that appears on the output of wsl -l -v
.Terminate a running distribution
I have covered this as a separate article as, how to shut down a WSL system. In short, if you want to terminate a running WSL distribution, run:
wsl --terminate <running_distribution_name>
Or, if you intend to shut down the entire WSL system, use:
wsl --shutdown
Get the WSL version installed on your system
There are two major versions for WSL; WSL 1 and WSL 2. WSL version 2 has several advanced features and is better compared to WSL 1.
But how would you check the version of WSL on your system? To do that, you can execute the command:
wsl --version
In the screenshot above, this command will print the version of WSL, the kernel version it is using, etc. You can see that I am running WSL 2 version.
Check WSL Status
You can check the status of WSL, its configuration, etc. using the --status
option.
wsl --status
Here, you can see that, I use WSL 2 as the default version. It also mentions that, WSL 1 is not configured properly, and what I should do to make it work.
Change the WSL version of a distribution
Let's say you are running a distribution using WSL 1, and you want to change the WSL version to 2 so that you can install Linux GUI apps with that system. For this, you can open a terminal in Admin mode and use the command below:
wsl --set-version <distribution name> <versionNumber>
So, in my case, I will use:
wsl --set-version Ubuntu 2
Export a distribution
Backing up data is always important, if you are dealing with critical information. In Linux distributions, we have tools like Timeshift, to create comprehensive system backups.
What about WSL? Yes, WSL provides a built-in method to take a backup of your installed distribution along with all the data.
WSL_Exports
and WSL_Imports
to keep the exported files and imported distributions. This way, you can avoid cluttering and easy data retrieval.To export a distribution, use the command inside the WSL_Exports
folder (for convenience):
wsl --export <distribution_name> <file_name.tar>
You are exporting the distribution along with the data to a tar file. The distribution_name
should be the proper name, as in the output of the command ws -l -v
.
Import a distribution
You have exported a distribution. Now, how will you restore it so that you can work with the data it carries? For this, on an elevated terminal, run the command:
wsl --import <Distribution Name> <Import location> <exported file>
Here, for future convenience, I am using a dedicated installation folder for the imports. So, my command will look like:
This will import the distribution from the file.
The imported distribution won't have a start menu entry so that you can open easily. This is the case, even if the original distribution had a start menu entry.
Ubuntu
already in place, use some other name.Unregister a distribution
To remove a distribution from the system, you can use the --unregister
option of WSL. First, list the distribution using wsl -l -v
. Note the name of the distribution and then perform the command:
wsl --unregister <distribution_name>
If you have installed the distribution from the list of available distributions (wsl --list --online
), you may also need to uninstall the app from the system too.
Update WSL
To update WSL from the command line, you can use the command below on an elevated terminal:
wsl --update
Get help
There are many options and sub commands for WSL, that you can utilize to get the most out of WSL. So, if you need any assistance regarding some options, always use the built-in help mechanism.
wsl --help
Wrapping Up
I have gone through several important commands, that you can use to manage various distributions.
If you are curious, you can download the cheat sheet given below, that lists some more commands, and their purposes.