1. 管理员打开PowerShell,开启WSL功能:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
2. 应用商店下载安装ubuntu
默认工作路径:
C:UsersabnkAppDataLocalPackagesCanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgscLocalState ootfs
Ubuntu中由apt-get获得的文件包保存在:
/var/cache/apt/archives
3. VMWare和Hyper-v冲突的解决:
bcdedit /set hypervisorlaunchtype off
重启或手动停止Hyper-v服务
bcdedit /set hypervisorlaunchtype auto
用VM就关,用Hyper-v就开
4. 更改源:
sudo cp /etc/apt/sources.list /etc/apt/sources.list_bak # sudo vim /etc/apt/sources.list
修改:
# :%s#security.ubuntu.com#mirrors.tuna.tsinghua.edu.cn#g # :%s#archive.ubuntu.com#mirrors.tuna.tsinghua.edu.cn#g # :%s#cn.mirrors.tuna.tsinghua.edu.cn#mirrors.tuna.tsinghua.edu.cn#g
# 18,20版本就用下面的就OK :%s#archive.ubuntu.com#mirrors.tuna.tsinghua.edu.cn#g
# 一行命令搞定
sed -i "s#archive.ubuntu.com#mirrors.tuna.tsinghua.edu.cn#g" /etc/apt/sources.list
# 对于CentOS,更改源先yum update, 然后 yum grouplist 再安装
sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' -i.bak /etc/yum.repos.d/CentOS-*.repo
其它:
sudo mv /etc/yum.repos.d/CentOS-Local.repo /etc/yum.repos.d/CentOS-Local.repo_bak yum clean all && yum makecache
生效:
sudo apt update
5. 安装gcc、g++
sudo apt-get install build-essential sudo apt install gcc g++ # 不要用这个了
以下内容将被安装:
The following NEW packages will be installed: binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3 libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev make manpages-dev
6. 升级WSL2
powershell开启管理员权限:
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
lsb_release -a # wsl内查看版本号