什么是 WSL
引用百度百科的一段话:
Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层。它是由微软与Canonical公司合作开发,目标是使纯正的Ubuntu 14.04 "Trusty Tahr"映像能下载和解压到用户的本地计算机,并且映像内的工具和实用工具能在此子系统上原生运行。
我们简单的认为它是在 Windows 上安装了一个 Linux 环境就好了。也就是最好的 Linux 发行版:Win10 + WSL (滑稽)。
安装 WSL
-
启用或关闭Windows功能
首先在搜索栏中搜索并打开“启用或关闭Windows功能”,勾选“适用于Linux的Windows子系统”项。只有开启这项设置才能正常安装WSL。 -
安装 WSL
在微软应用商店搜索 Linux,可以看到一系列 Linux 发行版,根据自己需要选择适合自己的发行版,这里我选用 Ubuntu 18.04 LTS,下载完成后启动,等待安装完成,输入账户和密码,我们便得到了一个 Linux 环境了。 -
WSL 文件位置
如果想在 Linux 查看其他分区,WSL 将其它盘符挂载在 /mnt 下。
如果想在 Windows 下查看 WSL 文件位置,文件位置在:C:\Users\用户名\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs 下。
默认安装位置
C:\Users\Administrator\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs
配置 WSL
更改源
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 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. 更新和升级
sudo apt-get update
sudo apt-get upgrade
WSL linux权限问题
wsl在mount windows系统到linux系统文件列表时候,所以权限都是777,但是在php执行chmod函数的时候,会提示“ chmod(): Operation not permitted”;
解决方法
vim /etc/wsl.conf
添加下面内容
[automount]
enabled = true
root = /mnt/
options = "metadata,umask=22,fmask=111"
mountFsTab = false
[filesystem]
umask = 022
重启WSL
管理员权限启动windows cmd命令行
net.exe stop LxssManager
之后在进入wsl系统,mnt目录下的文件权限会恢复到正常的权限;
网友评论