The introduction

Common ways to use a Linux environment under Windows are

  1. 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
  2. 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

  1. Install Ubuntu in the App Store
  2. To install it manually, visitDocs.microsoft.com/en-us/windo… 的Downloading distrosChapter, 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 Powershellwslorubuntu1804Quick access to WSL’s Ubuntu distribution for the reason thatubuntu1804.exeinC:\Users\[your username]\AppData\Local\Microsoft\WindowsAppsThis directory is the environment variable added by default
  • Ubuntu system files are locatedC: \ Users \ \ AppData \ [your username] Local \ Packages \ CanonicalGroupLimited Ubuntu18.04 onWindows_ \ LocalState \ [XXXXXXX] rootfs[XXXXXXX] indicates the preceding directoryThe installationThe software package suffix,
  • Disks in Windows are automatically mounted to the Ubuntu system/mntIn the directory, you can passdf -hormountView the mounting status
  • In Windows, to access Ubuntu in a directory and stay in that directory, press and holdShiftRight click and select Open hereLinux shell
  • Use the recommended change for the first time/etc/apt/source.listApt 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
  • UbuntusystemctlThe command cannot be used. Run the command to manually start the service/etc/init.d/[service name] startorService [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

  1. Microsoft-Windows Subsystem for Linux Installation Guide for Windows 10
  2. Microsoft-Manually download Windows Subsystem for Linux distro packages
  3. Microsoft-Initializing a newly installed distro
  4. Mavs have money – my play in the WSL series