Debian 10 更换 aliyun apt-get 源

该文介绍了如何将Debian10操作系统的apt-get源替换为阿里云镜像源,以加快在国内环境下安装软件包的速度。具体步骤包括备份原源文件,清除内容,添加阿里云源,以及更新apt。通过验证catsources.list和aptupdate的输出,确认阿里云源已成功设置。

概要

1、简介

将 Debian 10  的 apt-get 源更换为 aliyun,以提升国内环境 apt install 的速度。

2、版本信息

Debian 10
apt 1.8.2.1

详细步骤

1、备份原 apt-get 源文件

root@15ee503df884:~# cd /etc/apt
root@15ee503df884:/etc/apt# cp sources.list sources.list.bak

2、清除原 apt 源文件内容

root@15ee503df884:/etc/apt# > sources.list

3、添加 aliyun apt-get 源

root@15ee503df884:~# cd /etc/apt
root@15ee503df884:/etc/apt# echo "deb http://mirrors.aliyun.com/debian  stable main contrib non-free" >> sources.list
root@15ee503df884:/etc/apt# echo "deb http://mirrors.aliyun.com/debian  stable-updates main contrib non-free" >> sources.list

注:这里使用 echo 的方式配置是因为有可能有些系统中并未默认带有 vi 工具(比如 docker 镜像中的 debian 基础镜像中就不带 vi 工具)

4、更新 apt

执行如下命令更新 apt 源

root@15ee503df884:/etc/apt# apt update

验证总结

1、验证配置

执行 cat sources.list 查看文件内容,可以看到配置已经文件。再执行 apt update,如果输出内容中有包含 mirrors.aliyun.com,表示设置已经生效

root@15ee503df884:/etc/apt# cat sources.list
deb http://mirrors.aliyun.com/debian  stable main contrib non-free
deb http://mirrors.aliyun.com/debian  stable-updates main contrib non-free
root@15ee503df884:/etc/apt# apt update
Get:1 http://mirrors.aliyun.com/debian stable InRelease [121 kB]
Get:2 http://mirrors.aliyun.com/debian stable-updates InRelease [49.3 kB]
Get:3 http://mirrors.aliyun.com/debian stable/non-free amd64 Packages [87.7 kB]
Get:4 http://mirrors.aliyun.com/debian stable/main amd64 Packages [7905 kB]
Get:5 http://mirrors.aliyun.com/debian stable/contrib amd64 Packages [51.0 kB]
Get:6 http://mirrors.aliyun.com/debian stable-updates/main amd64 Packages [7380 B]
Fetched 8222 kB in 4s (2157 kB/s)                    
Reading package lists... Done

可以看到,文件内容已经更新,且 apt-get 的源已经切换到了 aliyun。完事收工!

附录

参考阿里云镜像站

https://developer.aliyun.com/mirror/debian

阿里云 debian 镜像支持版本

http://mirrors.aliyun.com/debian/dists/
### 更换 Debian 系统中 `apt-get` 更新的Debian 系统中,可以通过修改 `/etc/apt/sources.list` 文件来更改 APT 软件。以下是具体方法: #### 修改软件文件 1. 打开终端并编辑 `/etc/apt/sources.list` 文件: ```bash sudo nano /etc/apt/sources.list ``` 2. 替换现有的镜像地址为新的镜像地址。例如,如果当前使用的官方不可用或者速度较慢,可以选择国内的一些镜像站点,如阿里云、清华大学开软件镜像站等。 **阿里云镜像** 示例配置如下: ```plaintext deb http://mirrors.aliyun.com/debian/ buster main non-free contrib deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib deb http://mirrors.aliyun.com/debian-security buster/updates main deb-src http://mirrors.aliyun.com/debian-security buster/updates main deb http://mirrors.aliyun.com/debian buster-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian buster-updates main non-free contrib ``` 如果使用的是其他版本(如 bullseye 或 sid),需将 `buster` 替换为目标版本名称[^4]。 3. 保存并退出编辑器(Nano 编辑器下按 Ctrl+O 保存,Ctrl+X 退出)。 #### 验证新的有效性 完成上述操作后,执行以下命令验证新是否可用以及更新软件包列表: ```bash sudo apt-get update ``` 如果遇到 GPG 密钥错误,则需要导入相应的密钥。例如: ```bash sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXX ``` 其中 `XXXXXXXXX` 表示具体的密钥 ID[^3]。 #### 清理旧缓存数据 有时为了确保切换后的效果最佳,建议清理掉之前的APT缓存信息后再重新构建索引: ```bash sudo apt-get clean sudo rm -rf /var/lib/apt/lists/* sudo apt-get update ``` 通过以上步骤即可顺利完成Debian系统的APT更换过程[^5]。 ### 注意事项 - 不同国家和地区有不同的镜像服务器可供选择,请根据实际网络状况挑选最优选项。 - 切记每次调整完 sources.list 后都需要再次运行 `sudo apt-get update` 来刷新本地数据库记录。
### 配置适用于ARM架构的Debian系统中apt-get镜像Debian系统中,配置apt-get的镜像需要编辑`/etc/apt/sources.list`文件。对于ARM架构的Debian系统,官方提供了专门的APT支持,用户可以通过以下方法进行配置。 #### 1. 修改APT列表 打开`/etc/apt/sources.list`文件,使用文本编辑器(如`nano`或`vim`)进行编辑: ```bash sudo nano /etc/apt/sources.list ``` 根据Debian版本选择合适的APT地址。例如,对于Debian 11 (Bullseye),可以添加如下内容: ```plaintext deb http://deb.debian.org/debian bullseye main contrib non-free deb-src http://deb.debian.org/debian bullseye main contrib non-free deb http://deb.debian.org/debian-security bullseye-security main contrib non-free deb-src http://deb.debian.org/debian-security bullseye-security main contrib non-free deb http://deb.debian.org/debian bullseye-updates main contrib non-free deb-src http://deb.debian.org/debian bullseye-updates main contrib non-free ``` 上述配置适用于x86和ARM架构的Debian系统[^4]。 #### 2. 替换为国内镜像 为了提高下载速度,可以将官方替换为国内的镜像。以下是常用的国内镜像地址: - **阿里云**: ```plaintext deb http://mirrors.aliyun.com/debian/ bullseye main contrib non-free deb-src http://mirrors.aliyun.com/debian/ bullseye main contrib non-free deb http://mirrors.aliyun.com/debian-security bullseye-security main contrib non-free deb-src http://mirrors.aliyun.com/debian-security bullseye-security main contrib non-free deb http://mirrors.aliyun.com/debian bullseye-updates main contrib non-free deb-src http://mirrors.aliyun.com/debian bullseye-updates main contrib non-free ``` - **清华大学**: ```plaintext 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-security/ bullseye-security main contrib non-free deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security 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 ``` #### 3. 更新APT缓存 完成配置后,运行以下命令以更新APT缓存: ```bash sudo apt-get update ``` 如果出现错误提示,可能是因为APT配置不正确或网络连接问题,请检查并修正。 #### 4. 常见问题处理 - 如果遇到依赖性问题,可以尝试清理缓存并重新安装相关包: ```bash sudo apt-get clean sudo apt-get autoclean sudo apt-get -f install ``` 这些命令可以帮助解决由于软件包损坏或依赖性问题导致的错误[^3]。 - 如果APT无法解析某些包,可以尝试切换到其他镜像,或者检查系统的架构是否与APT兼容。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值