Ubuntu 修改成国内软件源(apt-get)

背景

 有时使用apt-get安装依赖库或软件时,看到15KB~40KB的速度下载,真的是恨铁不成刚,为什么不能快一些呢;明明电脑下载时都有1M~3M的,感到无奈,一直在等待安装。如果排除是电脑本身网络速度慢问题,那很有可能是安装依赖库或软件是外网的,需要从外网那里获取;这样自然就很慢啦。

 

修改成国内软件源(apt-get)

1. 备份原始文件

 2.修改 sources.list 文件的权限

3. 修改文件并添加国内源

 4.注释原文件内的源并添加如下地址 


1. 备份原始文件

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

 2.修改 sources.list 文件的权限

sudo chmod 777 /etc/apt/sources.list 

3. 修改文件并添加国内源

vi /etc/apt/sources.list

不喜欢用 vi 编译器的可以使用 gedit 

gedit /etc/apt/sources.list

 

 4.注释原文件内的源并添加如下地址 

不同的系统版本对应的软件源也是不一样的,之前被坑了;以为ubuntu系统下,使用的软件源应该都一样的,后来发现替换源后,部分软件无法安装,经过调查发现不同的系统版本对应的不同的软件源;

比如同一个品牌的软件源(网易163),也会区分是ubuntu18、ubuntu16还是ubuntu14系统的。

#阿里云 (推荐)Ubuntu18

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

 

#网易163(这个速度比较快)Ubuntu18

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

 

#阿里云 (推荐)Ubuntu16

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-proposed main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports 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-proposed main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

#网易163(这个速度比较快)Ubuntu16

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-proposed main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports 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-proposed main restricted universe multiverse  
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

 

#网易163(这个速度比较快)Ubuntu14

deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

软件源-分析

每一行的开头的deb或者deb-src,分别表示通过.deb文件、源文件的方式进行安装。URL后面的5个用空格隔开的字符串,分别对应相应的目录结构。

1)当我们打开URL,比如Ubuntu14 的网易软件源的,http://mirrors.163.com/ubuntu/ 会看到如下图的目录结构:

 

2)进入dists目录,可以发现trusty、trusty-security、trusty-updates、trusty-proposed、trusty-backports 五个目录:

3)trusty、trusty-security、trusty-updates、trusty-proposed、trusty-backports  后面四个字段对应子目录:

deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse

 

细心对比后会发现以下规律:

系统版本 Ubuntu14 Ubuntu16 Ubuntu18
软件源--关键字 trusty xenial bionic


5,更新源

sudo apt-get update

6. 更新软件( 可选)

sudo apt-get dist-upgrade
sudo apt-get upgrade

  由于包与包之间存在各种依赖关系。upgrade只是简单的更新包,不管这些依赖,它不和添加包,或是删除包。而dist-upgrade可以根据依赖关系的变化,添加包,删除包。

    upgrade:系统将现有的Package升级,如果有相依性的问题,而此相依性需要安装其它新的Package或影响到其它Package的相依性时,此Package就不会被升级,会保留下来. dist-upgrade:可以聪明的解决相依性的问题,如果有相依性问题,需要安装/移除新的Package,就会试着去安装/移除它. (所以通常这个会被认为是有点风险的升级) 

 

希望对你有帮助;

如果有更新或不对的地方欢迎指正。

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章