首先,我们要知道为什么要换apt源。因为Linux的发行版大多数都是默认使用国外的软件源,我国及周围(亚太)地区使用的都是默认的国外源,同步下载速度相应得会慢很多。如果修改为我们常用的或者离服务器最近的源站,就是非常高明的选择。
上述提到Debian,其实所有在用apt命令的Linux系统,都是基于Linux发行版Debian开发的,所以,只要是Debian系列的发行版都是支持apt命令的。本文中就是我们常见的Ubuntu系统,用来做例子。
注意,如果你的服务器是大厂服务器,那么不用更换源,因为大厂的服务器都有自己的镜像源。自带的源地址,下载速度可是比其他平台的快。
查看Ubutu版本代号(非常重要)
输入以下命令查看,务必记住这个jammy或者其他代号,后面要用到
lsb_release -c
![图片[1]-Ubuntu怎么换apt源地址-王先生笔记](https://wxsnote.cn/wp-content/uploads/2023/11/20231105194428343-1699184668-ddb0c98a14695fbb7c6ae7bf4dc165c6.png)
备份原apt源
为避免下载或修改失败,修改原来的源文件名,起到备份作用(修改名称后,就无法安装软件了,必须x修改成功或者改回原名)
sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup
操作有风险,建议给服务器新增快照,下面是恢复备份的方法
如果出现问题,进行该操作
删除错误文件(必须确认已经备份过安装源)
rm -rf /etc/apt/sources.list
将备份改回原名
mv /etc/apt/sources.list.backup /etc/apt/sources.list.backup
修改apt源配置文件
国内开源镜像平台有很多,我发现阿里云的源是多地区的,所以我们以阿里云源为例子
编辑sources.list文件
sudo vim /etc/apt/sources.list
按i键进入编辑模式,让后删除全部内容,再粘贴以下修改后的内容
deb http://mirrors.aliyun.com/ubuntu/ 版本代号 main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ 版本代号-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ 版本代号-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ 版本代号-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ 版本代号-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ 版本代号 main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ 版本代号-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ 版本代号-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ 版本代号-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ 版本代号-backports main restricted universe multiverse
务必修改汉字(版本代号)为前面提到的代号再粘贴到文件中
按Esc退出编辑,再输入:wq,再按回车退出
![图片[2]-Ubuntu怎么换apt源地址-王先生笔记](https://wxsnote.cn/wp-content/uploads/2023/11/20231105200143916-1699185703-60c4f5d02e5bd5ba2bf90ef83563a1b4.png)
更新apt
sudo apt update
sudo apt upgrade
至此结束,之前觉得下载安装程序很慢的,更换源后可以明显发现源文件下载速度变快
温馨提示:
本文最后更新于
登录后可快速点此处反馈,点击登录
2023-11-05 20:17:56,某些文章具有时效性,若有错误或已失效,请在下方留言或加入QQ群:
399019539 联系群主反馈。注意一些链接无法访问可能是你网络的原因,如Github,并非资源地址失效。
登录后可快速点此处反馈,点击登录
© 版权声明
THE END













请登录后查看评论内容