1.找到wsl镜像源
首先,我们找到自己的wsl镜像源所在的地方,在cmd中输入\wsl$
按enter可以看到自己的wsl在这里了
如果不想以后难找,可以通过给一个网络映射添加网络位置,这样就可以直接进入啦
完成之后就在网络位置可以看见快捷进入的文件夹了
打开文件夹,进入etc/apt文件夹,可以看见sources.list这一个文件,里面就是WSL-Ubuntu默认的apt源是国外的源。
2.替换镜像源
以下附各类国内镜像源:
阿里云:
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
中科大:
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
清华:
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
2.1 可以直接用记事本打开
直接将国内镜像ctrl+c、ctrl+v放入到sources.list里面
2.2 通过sudo进行修改
首先cd到镜像源目录下,为了确保 防止出现错误,用cp进行备份
使用sudo管理员权限,使用 vim 进行修改:
先不要按i、a、o进入编辑模式,如果按了可以通过esc取消。
我们先通过按ggdG这几个字母将里面的内容全部删除,
注:通过按下gg后发现光标移动到文件首行了。其中,gg为跳转到文件首行;dG为删除光标所在行以及其下所有行的内容。d为删除,G为跳转到文件末尾行;
然后按i、a、o将镜像源复制进去就行啦。
最后按esc,再按下:wq!就可以退出啦
3.更新镜像源列表
一次输入以下命令就可以更新啦
sudo apt-get update
sudo apt-get upgrade
我的因为更新过了,所以很快就结束了,没有装过的,可能会等几分钟,耐心等待就可以了。