一、备份apt源的配置文件
我们要修改的文件是
sources.list
,它在目录/etc/apt/
下,sources.list
是包管理工具apt
所用的记录软件包仓库位置的配置文件
,同样类型的还有位于 同目录下sources.list.d
文件下的各种.list
后缀的各文件。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
二、编辑apt源的配置文件
关于Vim介绍以及使用:https://blog.csdn.net/weixin_43438052/article/details/108743013
vim /etc/apt/sources.list
如果报错
sudo:vim:command not found
说明没装vim编辑器。安装命令:
sudo apt-get install vim
三、查看Ubuntu版本代号
- 使用命令查看Ubuntu的版本代号
Codename
:
lsb_release -c
# Codename: bionic
- 我用的是
Ubuntu18.04(LTS)
,其代号为bionic
Ubuntu 12.04 (LTS)
代号为precise
Ubuntu 14.04 (LTS)
代号为trusty
Ubuntu 15.04
代号为vivid
Ubuntu 15.10
代号为wily
Ubuntu 16.04 (LTS)
代号为xenial
Ubuntu 18.04 (LTS)
代号为bionic
四、更换apt源
-
sources.list
文件的条目都是有格式的,一般有如下形式:
# deb包
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
# 源码
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
-
Ubuntu
中软件包的分类是main
,restricted
,universe
,multiverse
快速切换源配置文件
- 建议备份保存为多个源(当网络出现问题时,可以换上切换!)
# 官方的源
/etc/apt/sources.list
# 阿里云
/etc/apt/sources.list.aliyun
# 清华
/etc/apt/sources.list.qinghua
- 当需要时,用命令切换
# 重命名
mv sources.list.aliyun sources.list
1. 阿里云
#deb包
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-backports main restricted universe multiverse
##测试版源
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed 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-backports main restricted universe multiverse
##测试版源
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# Canonical 合作伙伴和附加
deb http://archive.canonical.com/ubuntu/ bionic partner
deb http://extras.ubuntu.com/ubuntu/ bionic main
2. 清华大学镜像站
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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
五、执行更新
sudo apt-get update
六、更新软件
sudo apt-get upgrade