修改 WSL Ubuntu 18.04 默认源为阿里云镜像

更新日期: 2019-03-06 阅读次数: 43764 字数: 214 分类: Windows

Win10 Windows Store 中下载的 WSL Ubuntu 18.04 默认的源 apt install 下载速度异常缓慢,想替换成国内阿里云的镜像源

确认默认源

首先查看默认的源的地址

sudo vim /etc/apt/sources.list

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

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ bionic-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://archive.ubuntu.com/ubuntu/ bionic universe
# deb-src http://archive.ubuntu.com/ubuntu/ bionic universe
deb http://archive.ubuntu.com/ubuntu/ bionic-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates universe

...

修改默认源

首先将原配置文件备份

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

然后 VIM 打开,替换

:%s/security.ubuntu/mirrors.aliyun/g
:%s/archive.ubuntu/mirrors.aliyun/g

更新

sudo apt update

再使用 apt install 速度就快多了

参考

https://mirrors.aliyun.com/about

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式

谈笑风生

Amoy

请问一下楼主,我换了阿里和清华的源都无效,出现这样的情况:
:~$ sudo apt-get update                                                               Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease [242 kB]                  Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease [88.7 kB]         Err:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease                             Unknown error executing apt-key                                                            Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease [74.6 kB]       Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease [88.7 kB]        Err:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease                     Unknown error executing apt-key                                                            Err:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease                   Unknown error executing apt-key                                                            Err:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease                    Unknown error executing apt-key                                      
怎么解决啊?

lzjx

我也出现了这个,关了 VPX 后就可以了