The introduction
Common ways to use a Linux environment under Windows are
- Using mingw64, such as installing Git, will install this automatically. The advantage is that when you add its bin directory to the environment variable, it can be used directly at the command prompt or in Powershell
- The advantage of using Windows Subsystem for Linux (WSL) is that you can use all the functions of Linux exactly as you like. The disadvantage is that you have to enter the WSL environment to execute Linux commands. This article mainly introduces how to use Linux under Windows through mode 2
The installation
The preparatory work
Ensure that the system version is later than 14393. Run the following command at the command prompt to view the system version
systeminfo|findstr Build
Copy the code
Run the following command in Powershell(administrator rights) to enable the WSL function. After the WSL function is enabled, the system prompts you to restart the server. The WSL function takes effect after the server is restarted
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Copy the code
Install it in the App Store or download it manually
- Install Ubuntu in the App Store
- To install it manually, visitDocs.microsoft.com/en-us/windo… 的
Downloading distros
Chapter, select your preferred Linux distribution and click the link to download it.
The installation
In Powershell, go to the downloaded directory and install add-AppxPackage./[your distribution].appx, for example
Add - AppxPackage. \ CanonicalGroupLimited Ubuntu18.04 onWindows_1804. 2018.817.0 _x64__xxxxxxx. AppxCopy the code
Initialize the
Find Ubuntu 18.04 in the Start menu application. Click and wait for a minute or two to complete the initialization. Only the first click will require an initialization wait. Once the initialization is complete, you will be prompted to create a new user account. The user account name cannot be root, and the password you set will be used for sudo.
Use and Tips
- You can type at a command prompt or Powershell
wsl
orubuntu1804
Quick access to WSL’s Ubuntu distribution for the reason thatubuntu1804.exe
inC:\Users\[your username]\AppData\Local\Microsoft\WindowsApps
This directory is the environment variable added by default - Ubuntu system files are located
C: \ Users \ \ AppData \ [your username] Local \ Packages \ CanonicalGroupLimited Ubuntu18.04 onWindows_ \ LocalState \ [XXXXXXX] rootfs
[XXXXXXX] indicates the preceding directoryThe installation
The software package suffix, - Disks in Windows are automatically mounted to the Ubuntu system
/mnt
In the directory, you can passdf -h
ormount
View the mounting status - In Windows, to access Ubuntu in a directory and stay in that directory, press and hold
Shift
Right click and select Open hereLinux shell
- Use the recommended change for the first time
/etc/apt/source.list
Apt source - Ubuntu and the host share the same IP address by default. You can configure multiple IP addresses in the host network card and bind the IP in Ubuntu to make them different
- Ubuntu
systemctl
The command cannot be used. Run the command to manually start the service/etc/init.d/[service name] start
orService [service name] start
- Back up and restore the WSL, stopping the WSL before backing up
# # stop (the terminate) wsl -t <DistributionName> WSL --export Ubuntu d:\backup\Ubuntu-1804-20200426.tar wsl -export <DistributionName> <FileName> WSL --import ubuntu-1804-20200426 c:\WSL d:\backup\Ubuntu-1804-20200426.tar wsl --import <DistributionName> <InstallLocation> <FileName> Note that the file will be completely deleted wsl --unregister <DistributionName> ## Set distribution to default values -setdefault, -s wsl -s <DistributionName> Copy the code
- For details and more gameplay see another author of mavericks have Money – my playaround WSL series of articles
- Installing Docker (not recommended)
- Reference zhuanlan.zhihu.com/p/74489613
- Docker install: Module aufs not found
reference
- Microsoft-Windows Subsystem for Linux Installation Guide for Windows 10
- Microsoft-Manually download Windows Subsystem for Linux distro packages
- Microsoft-Initializing a newly installed distro
- Mavs have money – my play in the WSL series