您的当前位置:首页正文

ubuntu 22.04配置国内镜像源-2024.7月最新版

2024-11-07 来源:个人技术集锦

国内有很多Ubuntu 22.04的镜像源,包括阿里、网易,还有很多教育网的镜像源,比如清华源、中科大源。
在教程中我们将介绍如何更改镜像在ubuntu 22.04。国内的包括有镜像阿里云/163源/清华大学/中科大。

1、更换前的准备

首先我们需要先备份Ubuntu官方的软件源,执行以下命令将备份原来的软件源。

pokes@pokes-Virtual-Machine:/etc/apt$ sudo cp sources.list sources.list.bak

清空原有的sources.list

pokes@pokes-Virtual-Machine:/etc/apt$ sudo echo ``>sources.list
-bash: sources.list: 权限不够
提示权限不够,加了sudo也没用

只能切换root我们来尝试。之前18.04版本中切换root的方法:

pokes@pokes-Virtual-Machine:/etc/apt$ su root
密码: 
su: 认证失败

22.04已经不能用了,18.04版本中是可以用的。22.04新的方法是这样的:

sudo passwd root        #切换root,同时设置root密码
输入你的密码两次

2、更换源

复制以下命令即可一键切换到阿里云 ubuntu 22.04镜像:

sudo bash -c "cat << EOF > /etc/apt/sources.list && apt update
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
EOF"

清华大学镜像

sudo bash -c "cat << EOF > /etc/apt/sources.list && 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
EOF"

可以到这里验证一下:ubuntu | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

3、更新包

sudo apt-get update
sudo apt-get upgrade
Top