ubuntu server 22.04怎么切换国内镜像源
时间: 2023-09-13 13:11:29 浏览: 105
在 Ubuntu Server 22.04 中,可以通过以下步骤切换国内镜像源:
1. 打开终端,使用管理员权限登录(或使用 sudo 命令)。
2. 执行以下命令备份原有镜像源:
```
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
```
3. 执行以下命令编辑 sources.list 文件:
```
sudo nano /etc/apt/sources.list
```
4. 将原有镜像源地址注释掉,添加国内镜像源地址。例如,将原有的源地址:
```
deb http://archive.ubuntu.com/ubuntu/ focal main restricted
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
deb http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
deb http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb http://security.ubuntu.com/ubuntu/ focal-security universe
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse
```
改为以下国内镜像源地址:
```
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
```
5. 保存并关闭文件。
6. 执行以下命令更新软件源:
```
sudo apt-get update
```
7. 切换完毕后可以执行以下命令验证一下是否已经成功切换为国内镜像源:
```
cat /etc/apt/sources.list
```
如果输出的内容中包含了国内镜像源地址,则表示切换成功。
阅读全文