什么是 WSL
引用百度百科的一段話:
Windows Subsystem for Linux(簡稱WSL)是一個(gè)為在Windows 10上能夠原生運(yùn)行Linux二進(jìn)制可執(zhí)行文件(ELF格式)的兼容層。它是由微軟與Canonical公司合作開發(fā),目標(biāo)是使純正的Ubuntu 14.04 "Trusty Tahr"映像能下載和解壓到用戶的本地計(jì)算機(jī),并且映像內(nèi)的工具和實(shí)用工具能在此子系統(tǒng)上原生運(yùn)行。
我們簡單的認(rèn)為它是在 Windows 上安裝了一個(gè) Linux 環(huán)境就好了。也就是最好的 Linux 發(fā)行版:Win10 + WSL (滑稽)。
安裝 WSL
1. 啟用或關(guān)閉Windows功能
首先在搜索欄中搜索并打開“啟用或關(guān)閉Windows功能”,勾選“適用于Linux的Windows子系統(tǒng)”項(xiàng)。只有開啟這項(xiàng)設(shè)置才能正常安裝WSL。
2. 安裝 WSL
在微軟應(yīng)用商店搜索 Linux,可以看到一系列 Linux 發(fā)行版,根據(jù)自己需要選擇適合自己的發(fā)行版,這里我選用 Ubuntu 18.04 LTS,下載完成后啟動,等待安裝完成,輸入賬戶和密碼,我們便得到了一個(gè) Linux 環(huán)境了。

3. WSL 文件位置
如果想在 Linux 查看其他分區(qū),WSL 將其它盤符掛載在 /mnt 下。
如果想在 Windows 下查看 WSL 文件位置,文件位置在:C:/Users/用戶名/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc/LocalState/rootfs 下。
配置 WSL
1. 更改外觀設(shè)置
首先我們更改一下外觀,由于 WSL 的會話窗口配色實(shí)際上取決于 CMD 屬性里顏色標(biāo)簽里面的配色,默認(rèn)的實(shí)在是太丑了,既沒有高亮字符也不清晰,嚴(yán)重影響開發(fā)效率。
這就需要用到一個(gè)開源的 CMD 配色工具:ColorTool
下載解壓后,用 CMD 打開到解壓路徑,然后運(yùn)行下列的命令,CMD 的界面就會改變了,選一個(gè)自己覺得好看的。
colortool.exe -b deuteranopiacolortool.exe -b OneHalfDarkcolortool.exe -b OneHalfLightcolortool.exe -b solarized_darkcolortool.exe -b solarized_light
然后重新打開 Ubuntu 窗口,就會發(fā)現(xiàn)配色也被修改了。如果不滿意,還可以打開終端的設(shè)置屬性界面,微調(diào)下字體和光標(biāo)顏色等。這里建議將 ”將Ctr+Shift+ C/V用作復(fù)制/粘貼的快捷鍵” 給勾上,光標(biāo)形狀設(shè)置為實(shí)心框,字體設(shè)置為 Consolas。
2. 更改源
Ubuntu 默認(rèn)的 apt 源是國外的源,實(shí)在是太慢了,這里換成阿里云的源。
a. 首先復(fù)制源文件備份,便于以后恢復(fù):
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
b. 查看版本信息
lsb_release -c
Ubuntu 18.04 LTS 的代號是 :bionic
c. 編輯源文件
sudo vim /etc/apt/sources.list
根據(jù) Ubuntu 版本號,添加相應(yīng)內(nèi)容:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiversedeb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiversedeb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
新聞熱點(diǎn)
疑難解答
圖片精選