To install WSL Ubuntu 20.04.06 in a custom directory while retaining the default Ubuntu 20.04.3 installation, you must use the wsl --export and wsl --import commands. This process creates an isolated instance of the newer distribution at your specified path without affecting existing environments or system configurations.
Understanding the Dual Installation Strategy
By default, Windows Subsystem for Linux (WSL) installs distributions into a protected system location that is difficult to access directly. When you need a specific version like Ubuntu 20.04.06 alongside an older stable release such as Ubuntu 20.04.3, simply installing the new package will often overwrite or conflict with the existing one. The most robust solution is to export the desired version from Microsoft’s catalog and import it into a user-defined folder. This approach ensures that both versions can coexist, allowing you to switch between them using distinct window instances or terminal profiles. The core mechanism relies on two primary WSL management commands:wsl --export and wsl --import. The export command packages the root file system of a running distribution into a tarball, while the import command extracts that tarball into a new location and registers it as a separate WSL distribution. This method is particularly useful when you want to preserve the state of your original Ubuntu 20.04.3 installation while experimenting with updates or different configurations in the new environment.
Step-by-Step Installation Process
To begin, ensure that WSL is properly installed on your Windows machine. If you have not yet set up the infrastructure, refer to resources on Unable to Install WSL/Hyper-V on New Machine to troubleshoot any foundational issues before proceeding. Once WSL is active, you can proceed with the following steps to create the new Ubuntu instance. First, download the Ubuntu 20.04.06 distribution package. You can obtain this from the official Microsoft Store or by downloading the.appx file directly from the Ubuntu website. After downloading, you need to extract the rootfs. While you can use third-party tools, the most reliable method involves using PowerShell to handle the archive correctly. Create a temporary directory on your local drive where you will store the exported data and the final installation files.
Next, run the following command in PowerShell to export the default Ubuntu distribution if you wish to clone it, or more commonly, you will import a fresh copy. However, since we are targeting a specific minor version (20.04.06), it is often easier to download the tar.gz file associated with that release. Let us assume you have downloaded the ubuntu-20.04.06.tar.gz file. Navigate to your target installation directory in PowerShell. Then, execute the import command:
wsl --import Ubuntu20.04.06 C:\WSL\Ubuntu20.04.06 .\ubuntu-20.04.06.tar.gz
In this command, Ubuntu20.04.06 is the name of the new distribution, C:\WSL\Ubuntu20.04.06 is the absolute path where the files will be stored, and the final argument points to the downloaded tarball. Ensure that the destination folder does not already exist, as the import process will fail if the directory is present. This step effectively copies the file system to your chosen location and registers the new distro within WSL.
Configuring the New Environment
After the import completes, the new distribution is registered but may not have a default user configured. By default, WSL imports often start as the root user. To set up a standard user experience, you should launch the distribution and configure a username. Open PowerShell and type:wsl -d Ubuntu20.04.06
Once inside the new shell, you can add a regular user account using the adduser command. It is highly recommended to add this user to the sudo group to allow administrative privileges. For example:
sudo adduser [username]
sudo usermod -aG sudo [username]
Replace [username] with your desired login name. After setting the password and user details, you can exit the shell. To make this user the default for future sessions, you need to modify the configuration file located at /etc/wsl.conf inside the new distribution. Add the following lines to the file:
[user]
default=[username]
This configuration ensures that every time you launch Ubuntu20.04.06, you are automatically logged in as the non-root user, enhancing security and aligning with standard Linux practices.
Managing Multiple Distributions
With both Ubuntu 20.04.3 and Ubuntu 20.04.06 installed, you can manage them independently. Use the commandwsl -l -v to list all active distributions along with their versions and states. This output helps verify that both instances are running correctly and assigned to the correct paths. You can also assign specific port forwards or network settings to each distribution if needed, though they generally share the same host network interface.
If you encounter issues with package repositories, such as certificate verification errors, consult guides on Resolving Certificate Verification Failure in WSL Ubuntu for add-apt-repository to resolve SSL-related obstacles during software installation. This ensures that your new environment can fetch updates and install packages without interruption.
Finally, remember that storing WSL distributions in custom locations requires sufficient disk space and appropriate permissions. Regularly backing up the contents of your custom directory via wsl --export can prevent data loss if you ever need to migrate or reinstall the distribution.
Frequently Asked Questions
Can I delete the original Ubuntu 20.04.3 after importing the new version?
Yes, you can safely remove the original distribution using wsl --unregister Ubuntu if you no longer need it. However, be aware that this action permanently deletes all data stored within that specific instance, so ensure you have backed up any important files first. The new installation remains unaffected by this removal.
Why does my new WSL distribution start as root instead of my user?
This occurs because the wsl --import command does not automatically configure a default non-root user. You must manually create a user and update the /etc/wsl.conf file to set the default login identity. Without this configuration, WSL defaults to the root account for security reasons until explicitly changed.
Is it possible to share files between the two Ubuntu installations?
While the file systems are isolated, you can access both from Windows Explorer by navigating to the respective mount points or using the \\wsl$ network path. You can also sync data between them by copying files through the Windows host OS or by using shared volumes mounted within the WSL environment.
What happens if I try to import a distro to a folder that already exists?
The import process will fail if the destination directory is not empty or already exists. You must either choose a different path or delete the existing folder contents before running the import command. Always verify the target directory is clean to avoid permission errors or silent failures.
How do I switch between the two Ubuntu versions in Visual Studio Code?
You can select the specific WSL distribution from the bottom-left corner status bar in VS Code. Click the icon, choose "Connect to WSL," and then select the desired distribution name, such as Ubuntu20.04.06, from the list. This allows you to work in different environments simultaneously within the same editor session.