WSL2的正确打开方式

首先我废话一下WSL2的优点:

1. 传统的 VM 体验启动起来可能比较慢,隔离,消耗大量资源,并且需要您花费时间来管理它。Wsl2没有这些属性。

2.Wsl2中的 Linux 内核是由微软从最新的 stable 分支构建的,该分支基于 kernel.org 上提供的源代码。这个内核专门针对 wsl2进行了调优,对大小和性能进行了优化,以便在 Windows 上提供令人惊叹的 Linux 体验。内核将通过 Windows 更新提供服务,这意味着您将获得最新的安全修复和内核改进,而无需自己管理它。

3.诸如 git clone、 npm install、 apt update、 apt upgrade 等文件密集型操作在 WSL 2中都显著地提高了速度。

4.Wsl2在真正的 Linux 内核上使用一个轻量级实用程序 VM,内存占用很小。该实用程序将在启动时分配支持虚拟地址的内存。它被配置为以较小的总内存比例启动,这是 wsl1所需要的。

 

# 比较常用的一些命令

# 启动默认版本的wsl
wsl
# 查看当前的wsl版本以及状态
wsl -l -v  

# 立即终止所有正在运行的分发和 WSL 2 轻型工具虚拟机。
wsl --shutdown

# 查看当前的默认wsl
wsl --list

# 启动指定的wsl版本

# 如要启动Ubuntu20
wsl -d Ubuntu-20.04

# 如要启动Debian
wsl -d Debian

要使用WSL2 

需要做以下两点事:

1.安装WSL2内核 https://docs.microsoft.com/zh-cn/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package

2.切换wsl 版本为2

  • Powershell中使用以下命令可以将后续新装(从商店装)的其他发行版设置成使用wsl2。
wsl --set-default-version 2

 

  • Powershell中使用命令wsl --set-version Ubuntu 2可以将先有已安装的发行版换成wsl2的,Ubuntu换成你的发行版名字。
wsl --set-version Ubuntu-20.04 2
  • 等待 。或者重启。。

附上中国的/etc/apt/sources.list (实测与原默认路径的速度无差别 >_+...

如果切换记得备份原来的哦

sudo cp /etc/apt/sources.list /etc/apt/sources.list.20201225

sources.list

#deb cdrom:[Ubuntu 20.04.1 LTS _Focal Fossa_ - Release amd64 (20200731)]/ focal main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal universe
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner

deb http://security.ubuntu.com/ubuntu focal-security main restricted
# deb-src http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://security.ubuntu.com/ubuntu focal-security universe
# deb-src http://security.ubuntu.com/ubuntu focal-security universe
deb http://security.ubuntu.com/ubuntu focal-security multiverse
# deb-src http://security.ubuntu.com/ubuntu focal-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

完美!

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值