Skip to content

24.04 apt 换源

安装 ubuntu24.04

sh
docker run -it -p 8000:8000 --name test01 ubuntu:24.04

docker exec -it test01 bash

换源

apt源 文件位置:/etc/apt/sources.list.d/ubuntu.sources

先备份原来的:

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

自动选择最优镜像源

使用 mirror:// 协议

sh

echo '
Types: deb
URIs: mirror://mirrors.ubuntu.com/mirrors.txt
Suites: noble noble-updates noble-backports noble-security
Components: main restricted universe multiverse  
' > /etc/apt/sources.list.d/ubuntu.sources

使用指定镜像源

写入新源:

sh

echo '
# 阿里云
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
' > /etc/apt/sources.list.d/ubuntu.sources

或者直接替换:

sh
sudo sed -i "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list


sudo sed -i "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list.d/ubuntu.sources
sudo sed -i "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list.d/ubuntu.sources

sudo sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list.d/debian.sources

相关源集合

阿里云

# 阿里云
Types: deb
URIs: http://mirrors.aliyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

清华源

# 清华源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

中科大源

# 中科大源
Types: deb
URIs: http://mirrors.ustc.edu.cn/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

网易163源

# 网易163源
Types: deb
URIs: http://mirrors.163.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

华为云源

# 华为云源
Types: deb
URIs: http://repo.huaweicloud.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

腾讯云源

# 腾讯云源
Types: deb
URIs: http://mirrors.tencentyun.com/ubuntu/
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg