1.首先运行以下命令检查 Linux 操作系统版本
cat /etc/os-release
2.去阿里云镜像的官网获取与系统匹配的源
https://developer.aliyun.com/mirror/
3. 以 debian 11.x (bullseye) 版本的系统举例 (ubuntu系统同理)
编辑/etc/apt/sources.list文件(需要使用sudo), 在文件最前面添加以下条目(操作前请做好相应备份)
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib deb https://mirrors.aliyun.com/debian-security/ bullseye-security main deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
4.更新源以启用
sudo apt-get update
小知识:apt
和 apt-get
都是 Debian 和其衍生版本(如 Ubuntu)上的软件包管理工具
- apt-get 输出更稳定,适合脚本。
- apt 的输出通常更加清晰、有颜色标识,并且与用户的交互也更为友好。