写一个shell脚本替换apt-get源
时间: 2023-11-22 16:38:48 浏览: 153
好的,以下是一个简单的shell脚本,用于替换Ubuntu系统的apt-get源:
```bash
#!/bin/bash
# 备份旧的源列表文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 更新源列表文件
sudo cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
## 不建议自行添加,会导致软件不能更新 ##
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# Canonical 合作伙伴和附加软件包
deb http://archive.canonical.com/ubuntu focal partner
deb-src http://archive.canonical.com/ubuntu focal partner
EOF
# 更新源列表
sudo apt-get update
```
该脚本会将Ubuntu系统的apt-get源替换为阿里云的源,并备份旧的源列表文件。你可以将阿里云的源替换为其他镜像源。请注意,更换源可能会影响软件包的更新和安装。
阅读全文