天天看点

ubuntu更换软件源一、关于source.list文件二、源的选择 三、操作步骤四、关于更新软件

目录

一、关于source.list文件

二、源的选择

三、操作步骤

1、备份原始文件

2、更改软件源

3、更新源列表信息

四、关于更新软件

一、关于source.list文件

    文件/etc/apt/sources.list是一个普通可编辑的文本文件,保存了ubuntu软件更新的源服务器的地址。和sources.list功能一样的是/etc/apt/sources.list.d/*.list(*代表一个文件名,只能由字母、数字、下划线、英文句号组成)。sources.list.d目录下的*.list文件为在单独文件中写入源的地址提供了一种方式,通常用来安装第三方的软件。

    source.list内容:

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

具体含义:

1、每一行的开头是deb或者deb-src,分别表示直接通过.deb文件进行安装和通过源文件的方式进行安装。

2、deb或者deb-src字段之后,是一段URL,之后是五个用空格隔开的字符串,分别对应相应的目录结构。在浏览器中输入http://archive.ubuntu.com/ubuntu/,并进入dists目录,可以发现有5个目录和前述sources.list文件中的第三列字段相对应。任选其中一个目录进入,可以看到和sources.list后四列相对应的目录结构。如图:

ubuntu更换软件源一、关于source.list文件二、源的选择 三、操作步骤四、关于更新软件

更多内容可以使用man source.list获得。

3、关于前缀precise/trusty等区别,是指不同的版本代号

系统代号 版本
precise 12.04
trusty 14.04
vivid 15.04
xenial 16.04
zesty 17.04

查看本机版本代号:

[email protected]:/etc/apt$ lsb_release -a
No LSB modules are available.
Distributor ID:        Ubuntu                
Description:           Ubuntu 12.04.5 LTS    
Release:               12.04                 
Codename:              precise               
           

二、源的选择

    ubuntu官方有自身的软件源,直接从官方的软件源获取数据的速度比较慢。而通过国内的一些的源的镜像进行更新一般能够获得比官方源更快的速度,不过不同国内的源的下载速度也会不一样。

    该链接给出了详细的软件源信息:   http://wiki.ubuntu.org.cn/%E6%BA%90%E5%88%97%E8%A1%A8

对比aliyun、sohu、ubuntu官方ping的数据,可以发现aliyun的源在时延上表现最好。

ubuntu更换软件源一、关于source.list文件二、源的选择 三、操作步骤四、关于更新软件

三、操作步骤

1、备份原始文件

如果当前用户无权限需要切换用户

[email protected]:/etc/apt$ su root
Password: 
[email protected]:/etc/apt# cp /etc/apt/sources.list /etc/apt/sources.list.bak
[email protected]:/etc/apt# ls
apt.conf.d  preferences.d  sources.list  sources.list.bak  sources.list.d  trustdb.gpg  trusted.gpg  trusted.gpg~  trusted.gpg.d
           

2、更改软件源

# 覆盖sources.list内容
[email protected]:/home/picasso# cat >/etc/apt/sources.list << END
> deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
> deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
> deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
> END

# 查看sources.list内容
[email protected]:/home/picasso# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse

# 查看sources.list.bak内容对比
[email protected]:/home/picasso# cat /etc/apt/sources.list.bak
#deb cdrom:[Ubuntu 12.04 LTS _Precise Pangolin_ - Release i386 (20120423)]/ precise 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/ precise main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ precise main restricted

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

## ... source.list.bak备份文件内容过多不再赘述

           

3、更新源列表信息

ubuntu更换软件源一、关于source.list文件二、源的选择 三、操作步骤四、关于更新软件

四、关于更新软件

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

    由于包与包之间存在各种依赖关系。upgrade只是简单的更新包,不管这些依赖,它不添加包,或是删除包。而dist-upgrade可以根据依赖关系的变化,添加包,删除包。upgrade:系统将现有的Package升级,如果有相依性的问题,而此相依性需要安装其它新的Package或影响到其它Package的相依性时,此Package就不会被升级,会保留下来. dist-upgrade:可以聪明的解决相依性的问题,如果有相依性问题,需要安装/移除新的Package,就会试着去安装/移除它. (所以通常这个会被认为是有点风险的升级) 

参考内容:https://www.jianshu.com/p/dd233020c5b7

继续阅读