刚刚安装的Ubuntu24.04 由于源是国外,安装软件或者扩展特别慢,或者无法安装。现在更换其他apt安装源,包括阿里云、清华、中科大等源

1.首先备份 原来配置

sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.bak

2. 启用新的配置,以阿里云为例

sudo tee /etc/apt/sources.list.d/ubuntu.sources << 'EOF'
Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF

3. 如果新的配置更换其他配置

# 切换到中科大(推荐)
sudo sed -i 's|mirrors.aliyun.com|mirrors.ustc.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources && sudo apt update

# 切换到清华
sudo sed -i 's|mirrors.aliyun.com|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/ubuntu.sources && sudo apt update

# 切换到华为云
sudo sed -i 's|mirrors.aliyun.com|repo.huaweicloud.com|g' /etc/apt/sources.list.d/ubuntu.sources && sudo apt update

# 切换到腾讯云
sudo sed -i 's|mirrors.aliyun.com|mirrors.cloud.tencent.com|g' /etc/apt/sources.list.d/ubuntu.sources && sudo apt update

4.验证效果,直接 update 看情况

$ sudo apt update
Get:1 https://mirrors.aliyun.com/ubuntu noble InRelease [256 kB]
Get:2 https://mirrors.aliyun.com/ubuntu noble-updates InRelease [126 kB]
Get:3 https://mirrors.aliyun.com/ubuntu noble-backports InRelease [126 kB]

如果能快速更新,则更换成功。不行就更换下一个。