
我们在适用ubuntu等linux操作系统的时候,经常会用到系统自带的各种国外的源,因为国内网络环境的原因,访问速度非常慢,甚至直接无法适用,我们在腾讯云、阿里云等服务器商家购买的云服务相对好一些,因为他们大厂的网络基本上都是优化过的,但是如果是自己搭建的linux服务器,可能访问速度会很不理想,影响适用,所以把默认的源更换为国内的源很有必要,个人使用测试推荐清华的源不错 ,下面我们掩饰在ubuntu中更换清华的源。
环境
系统:ubuntu-22.04.1-live-server
源:清华ubuntu源(https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/)
教程开始
ssh登录ubuntu系统
切换为root登录,如果已经是root,就跳过。
su root
输入密码,回车
方法一:命令替换
执行如下命令自动替换
sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
方法二:手动替换
Ubuntu 的软件源配置文件是 /etc/apt/sources.list。
vi /etc/apt/sources.list
按下“i”键盘,删除原来的信息,粘贴下面的信息。
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src 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 universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
退出:按下键盘上 Esc键,按下:,输入 wq 按回车即可
其他系统和版本的切换方式
访问清华的源网站,选择自己的系统类型,使用类似的方式,根据页面的提示操作即可。
清华大学开源软件镜像站(https://mirror.tuna.tsinghua.edu.cn/)