How to Install Multiple Ubuntu Distros in WSL2
I recently wanted to experiment on a fresh installation of Ubuntu in WSL2. I couldn’t install another instance of the distro from Microsoft Store because I already had one. Luckily, there is a way to bypass this limitation. Using
wsl command you can install the same version of Ubuntu more than once.
Backing up Current Distro
Creating a backup of your current Ubuntu distribution is needed to create duplicate installations.
Launch Windows PowerShell and follow the steps to save a copy of your current environment.
List all available distributions by running
wsl -l -v NAME STATE VERSION * Ubuntu Running 2
Shutdown all distributions
wsl --exportcommand and pass it your distro’s name and your desired name for the backup file. It will create a tar archive.
wsl --export Ubuntu ubuntu.tar
Exporting can take a while depending on the amount of data in your distro. Be patient and you should see
ubuntu.tar file in your current working directory eventually.
Installing Multiple Instances
You can install as many instances of your distro as you want from the backup you created.
wsl --import command and provide a unique name for the distribution in the first option. In the second option provide a path where to install it. I have created a dedicated folder
wsl-instances for this. Lastly, specify the backup tar archive.
The example below installs two instances of your backed up distro.
wsl --import UbuntuCopy .\wsl-instances\UbuntuCopy ubuntu.tar wsl --import UbuntuAnotherCopy .\wsl-instances\UbuntuAnotherCopy ubuntu.tar
wsl -l -v to see the what you have just installed.
After installation you will have to change the default user back to what it was in your original installation.
Access the CLI of the installed distro
Create a config file
Insert the following setting
Go back to Windows PowerShell and shutdown the distro to restart it
You should see your user being used the next time you access the CLI of your distro.
Installing Clean Version
To install a clean version of your distro you have to delete the
Make sure you have the backup you created previously.
Destroy the current installation
wsl --unregister Ubuntu
Re-install Ubuntu running the following command
You should now have a clean installation of Ubuntu alongside the copy of your old distro that you created in the previous section.
You can repeat the entire process described previously to create an archive of the clean installation. You can then import a fresh distro whenever you one.
You learned to back up your current distribution and duplicate it into new instances. You also learned how to install a clean version of your distro without losing your original one.