什么是Ubuntu的软件源?
我们在使用Debian或者Ubuntu的apt-get工具来安装需要的软件时,其实就是从服务器获取需要安装的软件并把它安装在本地计算机的过程。所谓的软件源,就是我们获取软件的来源,它是定义在/etc/apt/sources.list文件里的。
官方的默认源是来自美国的us.archive.ubuntu.com和security.ubuntu.com。那么我们怎么样换成速度更快的国内源呢?很简单,把/etc/apt/sources.list文件复制备份一下,然后把原来的内容修改成国内源的网址即可。以下步骤说明以阿里云的源为例:
1、复制备份原来的配置文件
sudo cp /etc/apt/sources.list sources.list.bak
2、替换源
阿里云源的文件
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse ##测试版源 deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # 源码 deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse ##测试版源 deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # Canonical 合作伙伴和附加 deb http://archive.canonical.com/ubuntu/ xenial partner deb http://extras.ubuntu.com/ubuntu/ xenial main
也可以替换为网易的源
deb http://mirrors.163.com/ubuntu/ zesty main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ zesty-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ zesty-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ zesty-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ zesty-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ zesty main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ zesty-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ zesty-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ zesty-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ zesty-backports main restricted universe multiverse
执行apt-get update,apt-get upgrade
如果是添加的网易源,可能会发现会报错,apt-get: Could not resolve 'mirrors.163.com’的错误,这种原因其实是因为还缺少一个步骤,就是将添加的网址和IP进行映射,修改/etc/目录下的host文件。
通过ip.chinaz.com进行查询网址“mirrors.163.com”,对应的ip地址如下所示,然后将其添加到hosts文件里。
123.58.190.228 mirrors.163.com 123.58.190.236 mirrors.163.com
再执行apt-get update,apt-get upgrade就好了