You can use any Linux distribution inside of the Windows Subsystem for Linux (WSL), even if it is not available in the Microsoft Store, by importing it with a tar file.
This article shows how to import the Linux distribution, CentOS, for use with WSL by obtaining its tar file using a Docker container. This process can be applied to import any Linux distribution.
Obtain a tar file for the distribution
First you'll need to obtain a tar file that contains all the Linux binaries for the distribution.
You can obtain a tar file in a variety of ways, two of which include:
Download a provided tar file. You can find an example for Alpine in the "Mini Root Filesystem" section of the Alpine Linux downloads site.
Find a Linux distribution container and export an instance as a tar file. The example below will show this process using the CentOS container.
Obtaining a tar file for CentOS example
In this example, we'll use Docker inside of a WSL distribution to obtain the tar file for CentOS.
Use the command wsl -l -v to check which distributions you have installed.
Finally, use the command wsl -d CentOS to run your newly imported CentOS Linux distribution.
Add WSL specific components like a default user
By default when using --import, you are always started as the root user. You can set up your own user account, but note that the set up process will vary slightly based on each different Linux distribution.
To set up user account with the CentOS distribution we just imported, first open PowerShell and boot into CentOS, using the command:
PowerShell
wsl -d CentOS
Next, open your CentOS command line. Use this command to install sudo and password setting tools into CentOS, create a user account, and set it as the default user. In this example, the username will be 'caloewen'.
Opomba
You will want to add the username to the sudoers file so that enables the user to use sudo. The command adduser -G wheel $myUsername adds the user myUsername to the wheel group. Users in the wheel group are automatically granted sudo privileges and can perform tasks requiring elevated permission.
You must now quit out of that instance and ensure that all WSL instances are terminated. Start your distribution again to see your new default user by running this command in PowerShell:
PowerShell
wsl --terminate CentOS
wsl -d CentOS
You will now see [caloewen@loewen-dev]$ as the output based on this example.
You can create your own customized Linux distribution, packaged as a UWP app, that will behave exactly like the WSL distributions available in the Microsoft Store. To learn how, see Creating a Custom Linux Distribution for WSL.
Sodelujte z nami v storitvi GitHub
Vir za to vsebino najdete v storitvi GitHub, kjer lahko tudi ustvarite in pregledate težave in zahtevke za uveljavitev sprememb. Če želite več informacij, glejte naš vodnik za sodelavce.
Povratne informacije o izdelku Windows Subsystem for Linux
Windows Subsystem for Linux je odprtokodni projekt. Izberite povezavo za pošiljanje povratnih informacij:
In this module, you learn how to use the Windows Subsystem for Linux (WSL) with Visual Studio Code (VS Code). We explore the installation process and the basics of using WSL. Additionally, we install and utilize the Visual Studio Code WSL extension. Finally, we demonstrate how to debug and run Python code in VS Code within our WSL environment.