服务器设置
Debian 11 替换源
- 备份现有的 apt 源配置
cp /etc/apt/sources.list /etc/apt/sources.list_backup
- 替换为中科大源
cat > /etc/apt/sources.list << EOF
deb https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
EOF
- 替换为默认官方源
cat > /etc/apt/sources.list << EOF
deb https://deb.debian.org/debian/ bullseye main contrib non-free
deb-src https://deb.debian.org/debian/ bullseye main contrib non-free
deb https://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-src https://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb https://deb.debian.org/debian/ bullseye-backports main contrib non-free
deb-src https://deb.debian.org/debian/ bullseye-backports main contrib non-free
deb https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb-src https://deb.debian.org/debian-security/ bullseye-security main contrib non-free
EOF
- 替换为清华源
cat > /etc/apt/sources.list << EOF
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
EOF
- 替换为阿里云源
cat > /etc/apt/sources.list << EOF
deb https://mirrors.aliyun.com/debian/ bullseye main contrib non-free
deb-src https://mirrors.aliyun.com/debian/ bullseye main contrib non-free
deb https://mirrors.aliyun.com/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main contrib non-free
deb https://mirrors.aliyun.com/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main contrib non-free
deb https://mirrors.aliyun.com/debian-security/ bullseye-security main contrib non-free
deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main contrib non-free
EOF
- 更新 apt 索引
apt-get update
Debian 包管理系统
dpkg、apt-get、apt
dpkg
负责实际的安装工作。apt-get
提供了完整的dpkg
接口,功能强大但略显繁琐。输出格式稳定,更适合用于编写脚本,实现自动化管理。apt
是更友好、更易用的apt-get
版本,功能略有精简。不仅包含了apt-get
的所有功能,还新增了list
、search
等实用命令,功能更加全面。更适合日常使用。
常用命令:
apt 命令 | apt-get 命令 | 命令的功能 |
---|---|---|
apt install | apt-get install | 安装软件包 |
apt remove | apt-get remove | 移除软件包 |
apt purge | apt-get purge | 移除软件包及配置文件 |
apt update | apt-get update | 刷新存储库索引 |
apt upgrade | apt-get upgrade | 升级所有可升级的软件包 |
apt autoremove | apt-get autoremove | 自动删除不需要的包 |
apt full-upgrade | apt-get dist-upgrade | 在升级软件包时自动处理依赖关系 |
apt search | apt-cache search | 搜索应用程序 |
apt show | apt-cache show | 显示包的详细信息 |
apt 命令 | 命令的功能 |
---|---|
apt list | 列出包含条件的包(已安装、可升级等) |
apt edit-sources | 编辑源列表 |
apt-get update 和 upgrade 区别
apt-get update
apt-get update
命令用于更新软件包列表,即更新本地软件包索引数据库。当我们在系统中安装新软件或者更新现有软件之前,需要先更新软件包列表,以确保获取最新的软件包信息。- 更新软件包列表时,
apt-get
会访问软件源(repository)中的信息,并将本地的软件包索引与之同步。软件源是存储软件包的服务器,通常由 Linux 发行版的官方维护或者第三方提供。 - 更新软件包列表不会安装或者升级任何软件包,它只是将本地的软件包信息与软件源保持同步,使得后续的软件包操作可以基于最新的信息进行。
apt-get upgrade
apt-get upgrade
命令用于升级已经安装的软件包到最新版本。在执行apt-get upgrade
之前,通常需要先执行apt-get update
命令,以确保软件包列表是最新的。apt-get upgrade
会遍历已安装的软件包,查找是否有可用的更新版本。如果有更新版本的软件包,apt-get
会将其下载并安装,实现软件的升级。- 升级软件包时,
apt-get
会在不影响系统稳定性的前提下尽量保持向后兼容,以确保系统的稳定运行