[{"data":1,"prerenderedAt":331},["ShallowReactive",2],{"blog:\u002Fblog\u002Flinux\u002Fwsl":3},{"id":4,"title":5,"author":6,"body":7,"category":316,"date":317,"description":318,"draft":319,"extension":320,"image":321,"meta":322,"navigation":323,"path":324,"seo":325,"series":321,"seriesOrder":321,"seriesTitle":321,"stem":326,"tags":327,"updatedAt":321,"__hash__":330},"blog\u002Fblog\u002Flinux\u002Fwsl\u002Findex.md","安裝 WSL 教學","charles",{"type":8,"value":9,"toc":309},"minimark",[10,15,19,22,26,29,33,58,64,69,93,98,119,151,155,224,228,231,305],[11,12,14],"h2",{"id":13},"什麼是-wsl","什麼是 WSL",[16,17,18],"p",{},"Windows Subsystem for Linux (WSL) 可以讓你在 Windows 上運行 Linux 環境。你可以在不用安裝雙系統或是虛擬機 (VM) 的方式，以子系統的方式直接安裝任何 Linux 發行版在 Windows 上。只需要透過指令或應用程式啟動 WSL，幾秒鐘之後就可以喚醒一個完整的 Linux 系統。",[16,20,21],{},"WSL 目前版本 (2024 年 10 月) 為 WSL 2，目前發展的已經相當完善，可以簡易設定需要分配多少硬體資源給 Linux 系統，並且許多方便的功能都是開箱即用，例如網路共享、跨系統存取檔案等等。",[11,23,25],{"id":24},"如何操作-wsl","如何操作 WSL",[16,27,28],{},"你可以用 Windows 的檔案總管以圖形化的方式來存取 WSL 的檔案，也可以透過 CMD 或 PowerShell 進入指定的 Linux Distro 來操作完整的 Linux 系統。",[11,30,32],{"id":31},"以-windows-11-安裝-wsl指定-ubuntu-2404-lts","以 Windows 11 安裝 WSL，指定 Ubuntu 24.04 LTS",[34,35,36],"ul",{},[37,38,39,40,47],"li",{},"參考官方文件：",[41,42,46],"a",{"href":43,"rel":44},"https:\u002F\u002Flearn.microsoft.com\u002Fzh-tw\u002Fwindows\u002Fwsl\u002Finstall",[45],"nofollow","🔗 安裝 WSL",[48,49,50],"blockquote",{},[16,51,52,53],{},"若使用 Win 10，可以參考官網教學：",[41,54,57],{"href":55,"rel":56},"https:\u002F\u002Flearn.microsoft.com\u002Fzh-tw\u002Fwindows\u002Fwsl\u002Finstall-manual",[45],"🔗 Windows 10 安裝 WSL",[59,60,61],"ol",{},[37,62,63],{},"以管理員身分開啟 PowerShell 並執行以下指令",[48,65,66],{},[16,67,68],{},"啟用 WSL 子系統與虛擬機器平台",[70,71,76],"pre",{"className":72,"code":73,"language":74,"meta":75,"style":75},"language-PowerShell shiki shiki-themes material-theme-lighter github-light github-dark","dism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:Microsoft-Windows-Subsystem-Linux \u002Fall \u002Fnorestart\ndism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:VirtualMachinePlatform \u002Fall \u002Fnorestart\n","PowerShell","",[77,78,79,87],"code",{"__ignoreMap":75},[80,81,84],"span",{"class":82,"line":83},"line",1,[80,85,86],{},"dism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:Microsoft-Windows-Subsystem-Linux \u002Fall \u002Fnorestart\n",[80,88,90],{"class":82,"line":89},2,[80,91,92],{},"dism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:VirtualMachinePlatform \u002Fall \u002Fnorestart\n",[48,94,95],{},[16,96,97],{},"若遇到錯誤，可以嘗試也啟用 Hyper-V，並重啟電腦",[70,99,101],{"className":72,"code":100,"language":74,"meta":75,"style":75},"# 若上面指令都沒有問題，可以跳過這個步驟\ndism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:Microsoft-Hyper-V \u002Fall \u002Fnorestart\ndism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:Microsoft-Hyper-V-Hypervisor \u002Fall \u002Fnorestart\n",[77,102,103,108,113],{"__ignoreMap":75},[80,104,105],{"class":82,"line":83},[80,106,107],{},"# 若上面指令都沒有問題，可以跳過這個步驟\n",[80,109,110],{"class":82,"line":89},[80,111,112],{},"dism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:Microsoft-Hyper-V \u002Fall \u002Fnorestart\n",[80,114,116],{"class":82,"line":115},3,[80,117,118],{},"dism.exe \u002Fonline \u002Fenable-feature \u002Ffeaturename:Microsoft-Hyper-V-Hypervisor \u002Fall \u002Fnorestart\n",[59,120,121,134,137],{},[37,122,123,124,129],{},"到 ",[41,125,128],{"href":126,"rel":127},"https:\u002F\u002Fapps.microsoft.com\u002Fdetail\u002F9nz3klhxdjp5?hl=zh-tw&gl=TW",[45],"Microsoft Store 安裝 Ubuntu 24.04 LTS",[130,131],"img",{"alt":132,"src":133},"alt text","\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage.png",[37,135,136],{},"安裝完成後直接點擊開啟，會跳出視窗開始自動安裝",[37,138,139,140,145,148],{},"輸入使用者名稱與密碼，完成安裝",[48,141,142],{},[16,143,144],{},"密碼在輸入時不會顯示，輸入完後按下 Enter 即可",[146,147],"br",{},[130,149],{"alt":132,"src":150},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-1.png",[11,152,154],{"id":153},"進入-wsl-的幾種方式","進入 WSL 的幾種方式",[34,156,157,174,183],{},[37,158,159,160,162,163,166,167,170,171],{},"透過終端機進入",[146,161],{},"輸入 ",[77,164,165],{},"wsl"," 或 ",[77,168,169],{},"bash"," 即可進入 WSL\n",[130,172],{"alt":132,"src":173},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-2.png",[37,175,176,177,179,180],{},"透過 Windows 檔案總管",[146,178],{},"在檔案總管的左側選單可以看到 WSL 的 Distro，點擊進入後即可透過檔案總管操作 WSL 的檔案\n",[130,181],{"alt":132,"src":182},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-3.png",[37,184,185,186],{},"透過 VS Code 開啟 WSL",[59,187,188,194,200],{},[37,189,190,191],{},"點擊左下角的連結圖示\n",[130,192],{"alt":132,"src":193},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-4.png",[37,195,196,197],{},"找到 WSL 選項，第一次會提示需要安裝，點擊後會自動安裝\n",[130,198],{"alt":132,"src":199},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-5.png",[37,201,202,203,206,207,210,211,214,216,219,221],{},"再次點擊左下角的連結圖示，選擇 ",[77,204,205],{},"Connect to WSL"," (或 ",[77,208,209],{},"連線到 WSL"," )，即可開啟 WSL 的 VS Code\n",[130,212],{"alt":132,"src":213},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-6.png",[146,215],{},[130,217],{"alt":132,"src":218},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-7.png",[146,220],{},[130,222],{"alt":132,"src":223},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-8.png",[11,225,227],{"id":226},"配置-wsl-設定檔","配置 WSL 設定檔",[16,229,230],{},"透過 .wslconfig 檔案可以設定 WSL 的硬體資源分配，例如 CPU、記憶體等等。",[59,232,233,240],{},[37,234,235,236,239],{},"使用檔案總管進入 ",[77,237,238],{},"%userprofile%"," 目錄",[37,241,242,243,246,247,250,252,253,295],{},"新增一個文字檔，命名為 ",[77,244,245],{},".wslconfig"," 檔案\n右鍵以記事本或任何文字編輯器開啟\n",[130,248],{"alt":132,"src":249},"\u002Fimages\u002Fblog\u002Flinux\u002Fwsl\u002Fimage-9.png",[146,251],{},"寫入以下內容，可以自行調整硬體資源",[70,254,257],{"className":255,"code":256,"language":169,"meta":75,"style":75},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","[wsl2]\nmemory=8GB\nprocessors=6\n",[77,258,259,272,285],{"__ignoreMap":75},[80,260,261,265,269],{"class":82,"line":83},[80,262,264],{"class":263},"sP7_E","[",[80,266,268],{"class":267},"su5hD","wsl2",[80,270,271],{"class":263},"]\n",[80,273,274,277,281],{"class":82,"line":89},[80,275,276],{"class":267},"memory",[80,278,280],{"class":279},"smGrS","=",[80,282,284],{"class":283},"s_sjI","8GB\n",[80,286,287,290,292],{"class":82,"line":115},[80,288,289],{"class":267},"processors",[80,291,280],{"class":279},[80,293,294],{"class":283},"6\n",[48,296,297],{},[16,298,299,300],{},"更多設定參數可以參考官方文件：",[41,301,304],{"href":302,"rel":303},"https:\u002F\u002Flearn.microsoft.com\u002Fzh-tw\u002Fwindows\u002Fwsl\u002Fwsl-config#main-wsl-settings",[45],"🔗 WSL 2 設定檔",[306,307,308],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":75,"searchDepth":115,"depth":115,"links":310},[311,312,313,314,315],{"id":13,"depth":89,"text":14},{"id":24,"depth":89,"text":25},{"id":31,"depth":89,"text":32},{"id":153,"depth":89,"text":154},{"id":226,"depth":89,"text":227},"Linux","2024-10-05","透過 Windows Subsystem for Linux (WSL) 在 Windows 上安裝 Ubuntu 來使用 Linux 環境。",false,"md",null,{},true,"\u002Fblog\u002Flinux\u002Fwsl",{"title":5,"description":318},"blog\u002Flinux\u002Fwsl\u002Findex",[316,328,329],"Ubuntu","WSL","j78cmctfLXRta1Ydk4mYFoTDh4NhKy2DvIVdUjUl4MQ",1780512500858]