1、更换软件源
备份当前源:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
编辑源列表:
sudo vi /etc/apt/sources.list
填入当前版本推荐的源地址,保存后更新:
sudo apt update
2、不同系统版本的软件源推荐
2.1 Ubuntu 16.04 (Xenial)
阿里云
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
清华大学
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
中科大
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial universe
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates universe
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-updates multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-security universe
deb https://mirrors.ustc.edu.cn/ubuntu/ xenial-security multiverse
2.2 Ubuntu 18.04(Bionic)
阿里云
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe
deb http://mirrors.aliyun.com/ubuntu/ bionic multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-security universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-security multiverse
清华大学
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates multiverse
deb 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
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security multiverse
中科大
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic universe
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates universe
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security universe
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security multiverse
2.3 Ubuntu 20.04 (Focal)
阿里云
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
清华大学
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security multiverse
中科大
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ focal universe
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates universe
deb https://mirrors.ustc.edu.cn/ubuntu/ focal multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security universe
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security multiverse
2.4 Ubuntu 22.04 (Jammy)
阿里云
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates universe
deb http://mirrors.aliyun.com/ubuntu/ jammy multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ jammy-security universe
deb http://mirrors.aliyun.com/ubuntu/ jammy-security multiverse
清华大学
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security universe
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security multiverse
中科大
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy universe
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates universe
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-updates multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security main restricted
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security universe
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy-security multiverse
3、其它
3.1 apt update的作用
-
读取源列表:
apt
会读取/etc/apt/sources.list
文件及/etc/apt/sources.list.d/
目录下的所有文件,这些文件中列出了软件包源的地址。 -
连接软件源:
apt
会尝试连接到在源列表中指定的每个软件源(通常是远程服务器),以获取最新的软件包信息。 -
下载软件包索引:从每个软件源下载软件包索引文件。这些索引文件包含了可用软件包的名称、版本、描述以及依赖关系等信息。
-
更新本地缓存:将下载的软件包索引文件存储在本地缓存中,通常位于
/var/lib/apt/lists/
目录下。这样,系统在后续的安装或升级操作中可以快速访问这些信息。 -
检查更新:
apt
会检查已安装软件包的版本与软件源中提供的最新版本进行比较,以确定哪些软件包可以更新。 -
输出结果:最后,
apt
会在终端输出更新的结果,包括哪些软件包有可用的更新,以及它们的版本信息。
3.2 软件源解析
每一行指定了不同的软件源和组件,包括:
- main: 官方支持的软件包。
- restricted: 确保了对某些专有驱动的支持。
- universe: 社区维护的软件包。
- multiverse: 不受支持的软件包,可能涉及法律或版权问题。
- backports: 新版本的软件包,可用于旧版系统。
- security: 安全更新的软件包。
3.3 apt命令常用选项
命令 | 说明 |
apt update | 从配置的源中下载最新的软件包列表,以便系统知道可用的最新版本 |
apt upgrade | 升级所有已安装的软件包到最新版本,但不会安装新软件包或删除旧软件包 |
apt full-upgrade | 升级所有已安装的软件包,并根据需要安装新软件包或删除旧软件包,以满足依赖关系。 |
apt install <package-name> | 安装指定的软件包 |
apt remove <package-name> | 删除指定的软件包,但保留其配置文件 |
apt purge <package-name> | 删除指定的软件包及其配置文件 |
apt search <package-name> | 在软件包列表中查找指定的软件包 |
apt show <package-name> | 显示指定软件包的详细信息,包括版本、依赖关系和描述 |
apt autoremove | 删除系统中不再需要的依赖包,以释放空间 |
apt clean | 清理本地缓存的下载包,以释放磁盘空间 |
3.4 dpkg命令常用选项
命令 | 说明 |
sudo dpkg -i <package-file.deb> | 安装指定的.deb 软件包文件 |
sudo dpkg -r <package-name> | 卸载指定的软件包,但保留其配置文件 |
sudo dpkg --purge <package-name> | 用于完全卸载指定的软件包,包括其配置文件 |
dpkg -l | 列出系统中所有已安装的软件包 |
dpkg -l | grep <package-name> | 用于查找特定的软件包是否已安装 |
dpkg -s <package-name> | 显示指定软件包的详细信息,包括版本、依赖关系和描述 |
dpkg -c <package-file.deb> | 列出指定.deb 软件包中的文件 |
dpkg -L <package-name> | 列出已安装软件包的所有文件 |
dpkg -S <file-name> | 查找指定文件属于哪个已安装的软件包 |
sudo dpkg --configure -a | 配置所有未完全安装的软件包,通常用于修复安装过程中出现的问题 |