Tag Archive Windows

Byphunsanit

WSL: PowerShell Installing

การติดตั้ง Windows Subsystem for Linux 2 สำหรับลง linux ใน windows สามารถติดตั้งง่าย ๆ โดยใช้ PowerShell

  1. สร้างไฟล์ WSL2_install_Ubuntu.ps1 โดยมีเนื้อหา
    <#
    PowerShell install Windows Subsystem for Linux 2 (WSL2)
    #by pitt phunsanit
    https://pitt.plusmagi.com
    #>
    
    #Enabling Windows Services for the WSL.
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    
    #Windows' Virtual Machine Platform.
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
    #set the default version of the WSL to version 2.
    wsl --set-default-version 2
    
    #install WSL
    wsl --install -d Ubuntu
    
    #list installed distributions
    wsl -l -v

  2. เรียกใช้โดยเปิด PowerShell โดยสิทธิ์ administrator
  3. cd ไป folder ที่ save ไฟล์ WSL2_install_Ubuntu.ps1 เช่น cd C:\UsersGit\phunsanit\snippets\WSL
  4. run โดยใช้ .\WSL2_install_Ubuntu.ps1แล้ว enter แค่นี้ก็ติดตั้ง Ubuntu ใน windows ได้แล้ว
  5. เปิด terminal ใหม่ จะเห็นว่ามี Ubuntu เพิ่มขึ้นมา