鏡像下載、域名決議、時間同步請點擊 阿里云開源鏡像站
什么是WSL2
WSL全稱為Windows Subsystem for Linux,官網譯為:適用于 Linux 的 Windows 子系統 (WSL),
官方檔案直達:適用于 Linux 的 Windows 子系統檔案 | Microsoft Docs
WSL1和WSL2的比較:

為什么要WSL2
官方解釋:可讓開發人員直接在 Windows 上按原樣運行 GNU/Linux 環境(包括大多數命令列工具、實用工具和應用程式),且不會產生傳統虛擬機或雙啟動設定開銷,
我的觀點:日常生活中程式的開發離不開Linux,而Windows的GUI界面又是我們常用的(微信、Office等),我們可以有很多種方式使用Linux,如:

重點:Windows與Linux子系統將共用同一檔案系統!!! 我們可以在WSL中使用三劍客命令查詢分析windows檔案、日志、使用shell命令或者bash腳本運行存盤在windows中的linux程式、甚至在WSL中創建docker容器,在windows下使用docker desktop進行可視化管理,
總結:WSL2讓我們既擁有Windows的操作界面又擁有Linux的命令列工具,
啟用“虛擬機平臺”
WSL 2 需要啟用 Windows 10 的 “虛擬機平臺” 特性,它獨立于 Hyper-V,并提供了一些在 Linux 的 Windows 子系統新版本中可用的更有趣的平臺集成,
要在 Windows 10(2004)上啟用虛擬機平臺,請以管理員身份打開 PowerShell 或 cmd 并運行:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
要在 Windows 10(1903,1909)上啟用虛擬機平臺,請以管理員身份打開 PowerShell或 cmd 并運行:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
為了確保所有相關部件都整齊到位,您應該在此時重啟系統,否則可能會發現事情沒按預期進行,

安裝WSL2
本次安裝環境
處理器 Intel? Core? i5-10210U CPU @ 1.60GHz 2.11 GHz
機帶 RAM 8.00 GB (7.79 GB 可用)
系統型別 64 位作業系統, 基于 x64 的處理器
作業系統 Windows 10 家庭中文版
注意:本次安裝之前沒安裝過WSL和Ubuntu,只運行過VMware虛擬機,
檢查是否可以安裝
您的電腦需要以下配置:
- Windows 10 2020年5月(2004) 版, Windows 10 2019年5月(1903) 版,或者 Windows 10 2019年11月(1909) 版
- 一臺支持 Hyper-V 虛擬化的計算機
查看是否支持Hyper-V的方法:
- 打開cmd,輸入
systeminfo
- 查看Hyper-V資訊
比如我的電腦就可以支持

安裝WSL
用管理員身份運行PowerShell
wsl --install
–install 命令執行以下操作:
- 啟用可選的 WSL 和虛擬機平臺組件
- 下載并安裝最新 Linux 內核
- 將 WSL 2 設定為默認值
- 下載并安裝 Ubuntu Linux 發行版(可能需要重新啟動)
注意: 上述命令僅在完全未安裝 WSL 時才有效,如果運行 wsl --install 并查看 WSL 幫助文本,請嘗試運行 wsl --list --online 以查看可用發行版串列并運行 wsl --install -d

等待一會會,去打局游戲再回來…
順便查看了一下可以支持的linux系統,大便、Kali、OpenSUSE、烏班圖都有,默認安裝Ubuntu,
wsl --list --online

安裝了好一會兒了,,,,發現還是在85.7%,等不下去了CTRL+C了,
重新安裝,這次安裝指定的系統
wsl --install -d Ubuntu-20.04

重啟,然后成功了!
配置Linux
接下來打開已安裝的Ubuntu,這時候會提示你配置用戶和密碼
配置完畢!即可享用
測驗一下,用命令 cd / && ls -la 查看所有檔案,如下(是不是很熟悉)

更新一下鏡像源:
sudo vim /etc/apt/sources.list
將官方的源都注釋掉,換成的下面即可(我的是Ubuntu20.04,別的版本或者源可以自行網上搜)
- 阿里源
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
Debian系統分好幾種,wheezy、jessie、stretch、buster,它們分別對應:

Debian 11(Bullseye)國內鏡像源:
阿里
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
遇到問題:
Certificate verification failed: The certificate is NOT trusted——更新Ubuntu20.04、Debian11的程序中遇到的證書驗證失敗問題,
解決辦法:
- 更改源檔案,將所有的https改成http
sudo nano /etc/apt/sources.list
- 重新更新源
sudo apt update
- 安裝/更新證書ca-certificates
sudo apt install --reinstall ca-certificates
-
參照步驟一將鏡像源檔案改回https
-
再次更新源
sudo apt update && sudo apt upgrade
- 大功告成
安裝Windows Terminal
Windows Terminal能幫助我們管理命令列工具、PowerShell和WSL等Shell用戶的工具,能為我們提供最佳的 WSL 體驗,
下載方式
- https://www.microsoft.com/store/productId/9N0DX20HK701
- MicroSoft Store (微軟商店)找關鍵字 Windows Terminal

下載安裝即可,功能確實很多哈哈哈,效果:

遇到的問題:程序中下載失敗了好多次我不斷點擊重新下載才成功,
查看Linux版本資訊
- cat /etc/os-release

- cat /proc/version

- uname -a

- lsb_release -a

本文轉自:https://blog.csdn.net/weixin_51245887/article/details/124393376
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/494125.html
標籤:其他
上一篇:動態主機配置協議——DHCP詳解
