Recently I setup WSL under Windows 10 Professional to try out the capabilities and compare the functionality of Windows, Native Linux and Mac for development. I was unable to find a simple guide that outlined all the steps to get this up and running end to end when wanting to use multiple copies of the same linux instance type ie Ubuntu 20, this guide will hopefully solve that for you and provide some additional tips to setup your environment.
For the purpose of this guide we will use Ubuntu 20.04, however this should work with any of your favourite distributions.
There are quite a few steps, but once you have setup your environment it will be mostly care free.
Open a Powershell window as Administrator and run the following comments. This will setup WSL and set the default version to 2. Unless there is a specific reason to use version 1 I would highly recommend version 2.
To being setup we need to download the source file for the Linux distribution from Microsoft and extract it.
TIP: Make a Folder called WSL under you C:\ to keep the source files and keep your multiple distributions in a convenient location
Browse here and download Ubuntu 20.04: <https://docs.microsoft.com/en-us/windows/wsl/install-manual>
If/when this screen appears, just close it. We don’t need to install or Launch the image. This screen appears because I have already Installed the App from the store for an original Ubuntu 20.04 instance.
Go to download folder and extract the downloaded appx file (Use 7Zip or similar), you should end up with a folder something like the below.
Open a Powershell console as Administrator and run the below command.
NOTE: For each unique instance you will want a different Distro Name and Install Location, the filename is the source tar file we downloaded earlier. wsl --import <Distro> <InstallLocation> <FileName>
Once the import process has completed, Launch the new Instance, replacing the Distro Name with what you specified above. You should then be placed inside your new Linux distro instance.
At the linux CLI run the following, replacing ‘myusername’ with the username of your preference. Typically this will be the same username as the host, but can be what ever you wish.
At this point you are ready to use your new installation by running the following command from a powershell windows.
Here are a few extra items that will help your experience with WSL in generaly and especially when using multiple instances and importing of images.
When importing an image like we have here the normal wizard doesn’t run, so the instance will always run as root, this is undesirable. To change that you will need to use regedit. And add or set the ‘DefaultUid’ DWORD Value for each instance to the Linux UID of the user you would like to start the instance with. Typically the first user has an ID of 1000 decimal (0x03e8 hex), update this Value as you require. To change this back to root set it back to 0.
Follow these instructions to install from the App Store. This provides a single console window with a simple dropdown list of all your registered instances, and you can tab between them.
When using multiple instances of Linux windows terminal will show likely the same name on each tab (unless you are using a different user for each one). To set a static Tab Name for each instance go into settings in windows Terminal (in the dropdown instance list).
For each instance add the ‘tabTitle’ and ‘suppressApplicationTitle’ entries to each guid, and set the tabTitle to whatever you want.
You may want to export and import an image so you can install base packages and re-use image multiple times, or just be able to back it up or move to a new PC. You can use the ‘wsl –export’ command for this.
An example to export the image we created about would be the following (be sure to create the exports folder first)
If you haven't already downloaded and install Docker desktop do this now and enable the Docker WSL 2 engine, you can natively use docker from within your WSL instances with direct integration with Docker on the host.
NOTE: Don't forget to enable new distrubtions after you import them, docker WSL integration doesn't apply automatically
Windows Terminal Getting Started: https://docs.microsoft.com/en-us/windows/terminal/get-started
Windows terminal settings: https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-settings
Windows Subsystem Manual downloads: https://docs.microsoft.com/en-us/windows/wsl/install-manual