什么是 WSL
引用百度百科的一段話:
Windows Subsystem for Linux(簡(jiǎn)稱WSL)是一個(gè)為在Windows 10上能夠原生運(yùn)行Linux二進(jìn)制可執(zhí)行文件(ELF格式)的兼容層。它是由微軟與Canonical公司合作開(kāi)發(fā)春瞬,目標(biāo)是使純正的Ubuntu 14.04 "Trusty Tahr"映像能下載和解壓到用戶的本地計(jì)算機(jī),并且映像內(nèi)的工具和實(shí)用工具能在此子系統(tǒng)上原生運(yùn)行。
我們簡(jiǎn)單的認(rèn)為它是在 Windows 上安裝了一個(gè) Linux 環(huán)境就好了。也就是最好的 Linux 發(fā)行版:Win10 + WSL (滑稽)邢隧。
安裝 WSL
啟用或關(guān)閉Windows功能
首先在搜索欄中搜索并打開(kāi)“啟用或關(guān)閉Windows功能”,勾選“適用于Linux的Windows子系統(tǒng)”項(xiàng)仑氛。只有開(kāi)啟這項(xiàng)設(shè)置才能正常安裝WSL坝疼。安裝 WSL
在微軟應(yīng)用商店搜索 Linux搜贤,可以看到一系列 Linux 發(fā)行版,根據(jù)自己需要選擇適合自己的發(fā)行版钝凶,這里我選用 Ubuntu 18.04 LTS仪芒,下載完成后啟動(dòng),等待安裝完成耕陷,輸入賬戶和密碼桌硫,我們便得到了一個(gè) Linux 環(huán)境了。WSL 文件位置
如果想在 Linux 查看其他分區(qū)啃炸,WSL 將其它盤符掛載在 /mnt 下铆隘。
如果想在 Windows 下查看 WSL 文件位置,文件位置在:C:\Users\用戶名\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs 下南用。
默認(rèn)安裝位置
C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs
配置 WSL
更改源
Ubuntu 默認(rèn)的 apt 源是國(guó)外的源膀钠,實(shí)在是太慢了,這里換成阿里云的源裹虫。
a. 首先復(fù)制源文件備份肿嘲,便于以后恢復(fù):
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
b. 查看版本信息
lsb_release -c
Ubuntu 18.04 LTS 的代號(hào)是 :bionic
c. 編輯源文件
sudo vim /etc/apt/sources.list
根據(jù) Ubuntu 版本號(hào),添加相應(yīng)內(nèi)容:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.cm/untu/ bonic-proosed main restricted universe multiverse
保存并退出筑公。
d. 更新和升級(jí)
sudo apt-get update
sudo apt-get upgrade
WSL linux權(quán)限問(wèn)題
wsl在mount windows系統(tǒng)到linux系統(tǒng)文件列表時(shí)候雳窟,所以權(quán)限都是777,但是在php執(zhí)行chmod函數(shù)的時(shí)候匣屡,會(huì)提示“ chmod(): Operation not permitted”封救;
解決方法
vim /etc/wsl.conf
添加下面內(nèi)容
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=111"
mountFsTab = false
[filesystem]
umask = 022
重啟WSL
管理員權(quán)限啟動(dòng)windows cmd命令行
net.exe stop LxssManager
之后在進(jìn)入wsl系統(tǒng),mnt目錄下的文件權(quán)限會(huì)恢復(fù)到正常的權(quán)限捣作;