什么是 WSL
引用百度百科的一段話:
Windows Subsystem for Linux(簡稱WSL)是一個為在Windows 10上能夠原生運行Linux二進制可執行文件(ELF格式)的兼容層。它是由微軟與Canonical公司合作開發,目標是使純正的Ubuntu 14.04 "Trusty Tahr"映像能下載和解壓到用戶的本地計算機,并且映像內的工具和實用工具能在此子系統上原生運行。
我們簡單的認為它是在 Windows 上安裝了一個 Linux 環境就好了。也就是最好的 Linux 發行版:Win10 + WSL (滑稽)。
安裝 WSL
1. 啟用或關閉Windows功能
首先在搜索欄中搜索并打開“啟用或關閉Windows功能”,勾選“適用于Linux的Windows子系統”項。只有開啟這項設置才能正常安裝WSL。
2. 安裝 WSL
在微軟應用商店搜索 Linux,可以看到一系列 Linux 發行版,根據自己需要選擇適合自己的發行版,這里我選用 Ubuntu 18.04 LTS,下載完成后啟動,等待安裝完成,輸入賬戶和密碼,我們便得到了一個 Linux 環境了。
3. WSL 文件位置
如果想在 Linux 查看其他分區,WSL 將其它盤符掛載在 /mnt 下。
如果想在 Windows 下查看 WSL 文件位置,文件位置在:C:/Users/用戶名/AppData/Local/Packages/CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc/LocalState/rootfs 下。
配置 WSL
1. 更改外觀設置
首先我們更改一下外觀,由于 WSL 的會話窗口配色實際上取決于 CMD 屬性里顏色標簽里面的配色,默認的實在是太丑了,既沒有高亮字符也不清晰,嚴重影響開發效率。
這就需要用到一個開源的 CMD 配色工具:ColorTool
下載解壓后,用 CMD 打開到解壓路徑,然后運行下列的命令,CMD 的界面就會改變了,選一個自己覺得好看的。
colortool.exe -b deuteranopiacolortool.exe -b OneHalfDarkcolortool.exe -b OneHalfLightcolortool.exe -b solarized_darkcolortool.exe -b solarized_light
然后重新打開 Ubuntu 窗口,就會發現配色也被修改了。如果不滿意,還可以打開終端的設置屬性界面,微調下字體和光標顏色等。這里建議將 ”將Ctr+Shift+ C/V用作復制/粘貼的快捷鍵” 給勾上,光標形狀設置為實心框,字體設置為 Consolas。
2. 更改源
Ubuntu 默認的 apt 源是國外的源,實在是太慢了,這里換成阿里云的源。
a. 首先復制源文件備份,便于以后恢復:
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
根據 Ubuntu 版本號,添加相應內容:
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
新聞熱點
疑難解答