How to Install Multiple Instances of WSL2

How to Install Multiple Instances of WSL2

Perseus X's photo
Perseus X
·Jun 2, 2022·

2 min read

Requirement:

  • Windows 10 version 2004 or higher.
  • Windows Terminal or PowerShell
  • Ubuntu WSL tarball: Focal

Step 1: Install the latest version of WSL2

Type below command in Windows Terminal:

wsl --install

Step 2: Install the first instance of Ubuntu in WSL2

Also note that by using this method, you can store WSL data into any location you want, i.e. Drive D: instead of Drive C:

  • Replace the with the name you want to give, e.g. Ubuntu-Jammy,

  • Replace with the folder where you want to install the second instance of Ubuntu, i.e. D:\WSL\Ubuntu-Focal

  • Replace with the path of the Ubuntu WSL2 image tarball you downloaded earlier.

    wsl --import <Distribution Name> <Installation Folder> <Ubuntu WSL2 Image Tarball path>
    

    To check the list of distribution installed:

    wsl --list
    

Step 3: Login to the first instance of Ubuntu in WSL2

To login you need to run:

wsl -d <Distribution Name>

Step 4: Add new user

By default, you log in as root, enter below command to add new user and set password.

Replace with the username of your choice:

useradd -m -G sudo -s /bin/bash <USERNAME>
passwd <USERNAME>

Next, we need to configure Ubuntu to log in as your new user instead of root.

tee /etc/wsl.conf <<_EOF
[user]
default=<USERNAME>
_EOF

Exit, shutdown WSL and log in into Ubuntu again.

exit
wsl --shutdown
wsl -d <Distribution Name>

To install another instance of Ubuntu, just repeat Step 2 to 4. Enjoy!

Source: Cover image

 
Share this