什么是WSL
引用百度百科的一段话:
Windows Subsystem for Linux(简称WSL)是一个为在Windows 10上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层。它是由微软与Canonical公司合作开发,目标是使纯正的Ubuntu 14.04 "Trusty Tahr"映像能下载和解压到用户的本地计算机,并且映像内的工具和实用工具能在此子系统上原生运行。
安装WSL
1. 启用或关闭Windows功能
在"控制面板"->"程序和功能"->“启用或关闭Windows功能”,勾选“适用于Linux的Windows子系统”项。只有开启这项设置才能正常安装WSL。
2. 安装 WSL
在微软应用商店搜索 Linux,可以看到一系列 Linux 发行版,根据自己需要选择适合自己的发行版,这里我选用 Ubuntu 18.04 LTS,下载完成后启动,等待安装完成,输入账户和密码,我们便得到了一个 Linux 环境了。
新安装了WSL-Ubuntu
默认的apt
源是国外的源。国内访问速度会很慢。所以更改国内源是非常有必要的。
步骤:
- 备份list文件
cd /etc/apt/
sudo cp sources.list sources.list.bak
- 修改list文件
sudo vim sources.list
等等用vim打开以后好像不会修改,尴尬~~幸好wsl和主机win10系统文件可以相互访问,所以可以将sources.list拷贝到win10目录,改好之后在移回来。/mnt/d对应win10的d盘
cp sources.list /mnt/d
cp /mnt/d/sources.list sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
- 更新软件列表
sudo apt-get update
sudo apt-get upgrade
注意:ubuntu18.04是bionic,如果您是其他版本,可以先用指令查看系统版本(代号),然后在修改sources.list文件。
lsb_release -c