Linux配置软件源

Linux配置软件源

yum源配置文件说明

yum客户端配置文件

  • 为每个仓库单独提供的配置文件: /etc/yum.conf

  • 为所有仓库提供公共配置: /etc/yum.repos.d/*.repo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# yum配置文件示例说明: 
[epel] #id名称,可以自定义,保证唯一
name=Extra Packages for Enterprise Linux 7 - $basearch #repo的描述,$basearch为系统架构
baseurl=http://mirrors.aliyun.com/epel/7/$basearch #服务器的地址,file://本地地址;网络地址http://;https://;ftp://;可设置多个
enabled=1 #可以不写,默认值就是1,为启用;0为不启用
gpgcheck=0 #安装包时的校验,0为不校验,1为安装前校验,效验要导入密钥
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 #密钥,本地在/etc/pki/rpm-gpg下,由yum源提供

# repo文件中的变量:
# $releasever:当前os发行版的主版本号,如6;7;8;等
# $arch:CPU架构,如x86_64等
# $basearch:系统基础架构如x86_64等
# $contentdir:表示目录,如centos-7等
# 注意: yum仓库指向的路径一定必须指定到repodata目录所在目录
# 注意,如果需要启用其中一些 repo,需要将其中的 enabled=0 改为 enabled=1

# CentOS8 分为两个源 baseos、AppStream
BaseOS
#光盘本地路径,需要先挂载
file:///mnt/BaseOS/
#腾讯
https://mirrors.cloud.tencent.com/centos/$releasever/BaseOS/$basearch/os
#网易
https://mirrors.163.com/centos/$releasever/BaseOS/$basearch/os/

AppStream
#光盘本地路径,需要先挂载
file:///mnt/AppStream/
#腾讯
https://mirrors.cloud.tencent.com/centos/$releasever/AppStream/$basearch/os/
#网易
https://mirrors.163.com/centos/$releasever/AppStream/$basearch/os/

# CentOS7 base
#腾讯
https://mirrors.cloud.tencent.com/centos/$releasever/os/$basearch/
#网易
https://mirrors.163.com/centos/$releasever/os/$basearch/

# EPEL
CentOS8
#腾讯
https://mirrors.cloud.tencent.com/epel/$releasever/Everything/$basearch/
#华为
https://mirrors.huaweicloud.com/epel/$releasever/Everything/$basearch/
#清华大学
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/Everything/$basearch/
CentOS7
#腾讯
https://mirrors.cloud.tencent.com/epel/$releasever/$basearch/
#华为
https://mirrors.huaweicloud.com/epel/$releasever/$basearch/
#清华大学
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch/

配置ISO本地源

Centos 使用 ISO 光盘文件作为本地源

将系统 iso 镜像文件挂载到 CD/DVD 驱动器上,或者上传 iso 镜像文件至服务器上. 配置本地源,创建 cdrom.repo 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mkdir -p /mnt/centos/          # 创建本地源文件夹
mount /dev/sr0 /mnt/centos # 挂载镜像文件至指定的目录
cp -rf /etc/yum.repos.d /etc/yum.repos.d_$(date '+%Y%m%d_%H%M%S') # 备份原本地源
rm -rf /etc/yum.repos.d/* # 删除默认本地源

# centos 7
cat > /etc/yum.repos.d/cdrom.repo <<-EOF
[iso]
name=cdrom
baseurl=file:///mnt/centos/
gpgcheck=0
enabled=1
EOF

# centos 8及之后
cat > /etc/yum.repos.d/cdrom.repo <<-EOF
[BaseOS]
name=cdrom
baseurl=file:///mnt/centos/BaseOS/
gpgcheck=0
enabled=1

[AppStream]
name=cdrom
baseurl=file:///mnt/centos/AppStream/
gpgcheck=0
enabled=1
EOF

加载本地 yum 源&测试

1
2
3
yum clean all    # 清除yum缓存
yum makecache # 缓存本地yum源
yum list # 测试yum本地源 ,列出所有rpm包

Centos使用脚本配置本地源

示例脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
vim /root/auto_source.sh
#!/bin/bash
# 创建本地源文件夹
mkdir -p /media/centos/
# 挂载镜像文件至指定的目录
mount /dev/sr0 /media/centos
# 备份原本地源
cp -rf /etc/yum.repos.d /etc/yum.repos.d_$(date '+%Y%m%d_%H%M%S')
# 删除默认原本地源
rm -rf /etc/yum.repos.d/*
# 配置本地源,创建cdrom.repo文件,并配置如下内容
cat > /etc/yum.repos.d/cdrom.repo <<EOF
[iso]
name=cdrom
baseurl=file:///media/centos/
gpgcheck=0
enabled=1
EOF
# 清除yum缓存
yum clean all
# 缓存本地yum源
yum makecache

Ubuntu使用 ISO 光盘文件作为本地源

APT包索引配置文件

1
2
/etc/apt/sources.list 
/etc/apt/sources.list.d

首先将 ISO 文件挂载到服务器

1
2
3
4
mkdir /media/cdrom     # 创建挂载目录 
#-t 指定挂载类型 ;-O loop:用来把一个文件当成硬盘分区挂接上系统 ;
mount -t iso9660 /dev/cdrom /media/cdrom # 或者 mount -t auto /dev/cdrom /media/cdrom
sudo apt-cdrom -m -d=/media/cdrom add # 添加本地目录到软件源

配置源地址

1
2
3
4
5
6
7
# apt源的地址,该文件中包含很多在线源,如果不用在线的软件源,则将其他的注释掉只保留本地源即可
vim /etc/apt/sources.list
deb cdrom:[Ubuntu-Server 18.04.5 LTS _Bionic Beaver_ - Release amd64 (20200810)]/ bionic main restricted
# 进行本地库依赖更新
apt-get update
#升级软件包
apt-get upgrade

搭建本地私有 yum 仓库

下载所有yum仓库的相关包和meta 数据

1
2
3
4
5
6
7
# CentOS 8 dnf 工具集成
dnf reposync --help # 查看帮助
# 默认只下载rpm包,不下载 meta数据,需要指定--download-metadata 才能下载 meta
dnf reposync --repoid=epel --download-metadata -p /path

# CentOS 7 以前版本,reposync工具来自于yum-utils包
reposync --repoid=epel --download-metadata -p /path

方式一: 创建局域网的基于ISO光盘的私有yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 安装需要联网或者更改yum源路径为光盘路径
yum -y install httpd
systemctl enable --now httpd
# 挂载光盘,需要事先将光盘文件复制到服务器中
mkdir -pv /mnt/centos/{7,8}
mount /root/CentOS-7-x86_64-Everything-2009.iso /mnt/centos/7
mount /root/CentOS-8.3.2011-x86_64-dvd1.iso /mnt/centos/8
# 复制文件到httpd默认web目录中
cp -a /mnt/* /var/www/html/centos/8

# centos 7 yum客户端配置
cat > /etc/yum.repos.d/test.repo<<-EOF
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.8/centos/8/BaseOS
gpgcheck=0
enabled=1

# centos 8 yum客户端配置
cat > /etc/yum.repos.d/test.repo<<-EOF
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.8/centos/8/BaseOS
gpgcheck=0
enabled=1

[AppStream]
name=Appstream
baseurl=http://10.0.0.8/centos/8/AppStream/
gpgcheck=0
enabled=1
EOF

方式二: reposync下载阿里云的EPEL源,制作私有yum源

https://cloud.tencent.com/developer/article/1444713

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 首先配置好yum服务器的源,可查看下面的<配置 Centos 网络yum源>一节

# 安装需要联网或者更改yum源路径为光盘路径
yum -y install httpd
systemctl enable --now httpd

[root@centos8 ~]#dnf repolist
Last metadata expiration check: 0:07:40 ago on Sun 22 Dec 2019 03:14:16 PM CST.
repo id repo name status
AppStream AppStream 4,681
BaseOS BaseOS 1,655
epel EPEL 3,707

# 下载相关仓库包和元数据,CentOS 8 写法, --download-metadata 加此选项可以下载元数据
dnf reposync --repoid=epel --download-metadata -p /var/www/html
# CentOS 7 以前版本,reposync工具来自yum-utils包,没有先安装yum -y install yum-utils
reposync --repoid=epel --download-metadata -p /var/www/html
# 下载相关的key文件
wget -P /var/www/html/epel/ https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
# 下面两个步骤只有centos 7 没meta数据才需要执行,createrepo命令对/var/www/html/epel下的 rpm包创建为本地的 YUM 仓库,目的是为生成repodata目录并自动创建索引信息
#[root@centos7 ~]# yum -y install createrepo httpd
#[root@centos7 ~]# createrepo -pdo /var/www/html/epel/ /var/www/html/epel/

# 查看下载的文件,启动httpd
[root@centos8 ~]#ls /var/www/html/epel/
Packages repodata
[root@centos8 ~]# systemctl start httpd

# 为保证本地yum源能和阿里云镜像源同步,可以通过脚本定时任务实现(Centos7)
vim /root/yum-update.sh
#!/bin/bash
datetime=`date +"%Y-%m-%d"`
exec > /var/log/epel.log   #同步日志输出
reposync -d -r epel -p /var/www/html/   #同步镜像源
if [ $? -eq 0 ];then
createrepo --update /var/www/html/epel   #每次添加新的rpm时,必须更新epel索引信息
echo "SUCESS: $datetime epel update successful"
else
echo "ERROR: $datetime epel update failed"
fi
# 定时任务:每周六凌晨三点同步yum源
crontab -e
3 * * 6 /bin/bash/root/yum-update.sh

# centos 8 客户端yum源配置
[root@repo-client ~]# vim /etc/yum.repos.d/centos8.repo
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.8/centos/8/BaseOS
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[AppStream]
name=Appstream
baseurl=http://10.0.0.8/centos/8/AppStream/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

[extras]
name=extras
baseurl=http://10.0.0.8/centos/extras/
gpgcheck=0
enabled=1

[epel]
name=epel
baseurl=http://10.0.0.8/epel/
gpgkey=http://10.0.0.8/epel/RPM-GPG-KEY-EPEL-8
gpgcheck=0
enabled=1

方式三: rsync同步公网的yum仓库

使用rsync来和公网的yum仓库同步,推荐使用此方法同步,特别是在网络不稳定容易中断的情况下,因为rsync是快速增量备份工具,它能从上次中断的文件后继续同步,缺点是很多门户网站yum源不支持rsync同步。

因为这里直接下载了公网yum源的repo文件,所以不需要再用createrepo来创建索引了,同步完之后就直接可以用了。

centos 7

Base包和相关repo文件

1
2
3
4
5
6
# 安装需要联网或者更改yum源路径为光盘路径
yum -y install httpd
systemctl enable --now httpd

rsync -avrtzH --delete --delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/ /var/www/html/centos/7/os/x86_64/Packages/ > /tmp/rsyncbase.log 2>&1
rsync -avrtzH --delete --delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/repodata/ /var/www/html/centos/7/os/x86_64/repodata/ > /tmp/rsyncbaserepo.log 2>&1

Update包和相关repo文件

1
2
rsync -avrtzH --delete --delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/updates/x86_64/Packages/  /var/www/html/centos/7/updates/x86_64/Packages/ > /tmp/rsyncupdate.log 2>&1
rsync -avrtzH --delete --delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/updates/x86_64/repodata/ /var/www/html/centos/7/updates/x86_64/repodata/ > /tmp/rsyncupdaterepo.log 2>&1

epel的扩展包

1
rsync -avrtzH --delete --delay-updates --exclude=SRPMS/ --exclude=aarch64/ --exclude=ppc64/ --exclude=ppc64le/ --exclude=x86_64/debug/ rsync://rsync.mirrors.ustc.edu.cn/epel/7/  /var/www/html/epel/7/  > /tmp/rsyncepel.log 2>&1

客户端配置repo文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
vim /etc/yum.repos.d/centos7.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://10.100.10.89/centos/$releasever/os/$basearch/
enable=1
gpgcheck=0

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://10.100.10.89/centos/$releasever/updates/$basearch/
enable=1
gpgcheck=0

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://10.100.10.89/centos/$releasever/extras/$basearch/
enable=1
gpgcheck=0

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://10.100.10.89/centos/epel/7/$basearch
enabled=1
gpgcheck=0

yum clean all
yum makecache

参数说明-a, –archive 归档模式,表示以递归方式传输文件,并保持所有文件属

1
2
3
4
5
6
7
8
9
-v, --verbose 详细模式输出
-r, --recursive 对子目录以递归模式处理
-t, --times 保持文件时间信息
-z, --compress 对备份的文件在传输时进行压缩处理
-H, --hard-links 保留硬链接
--delete 删除那些DST中SRC没有的文件
--delay-updates 在传输末尾把所有更新的文件放到位
--exclude=PATTERN 指定排除不需要传输的文件模式
--include=PATTERN 指定不排除而需要传输的文件模式

配置网络源

镜像站

序号 镜像站名称 Kali Rocky AlmaLinux EPEL Fedora openEuler OpenCloudOS
1 阿里云
2 腾讯云
3 华为云
4 网易
5 搜狐
6 清华大学
7 北京大学
8 浙江大学
9 南京大学
10 重庆大学
11 兰州大学
12 上海交通大学
13 哈尔滨工业大学
14 中国科学技术大学
15 中国科学院软件研究所

使用建议

上述列表中的镜像站均支持 Debian Ubuntu CentOS openSUSE Arch Linux 软件源,列表根据单位性质、地理位置、名称长度进行排序与实际速度无关

软件源的速度区分刷新速度和下载速度,后者才是关键,具体请结合实际地理位置选择尝试,华北地区建议优先使用 中科大、腾讯云 镜像站,你可以使用下面提到的辅助工具网站来帮助你进行选择

目前不建议使用 阿里云 镜像站,由于使用人数过多其公网下行带宽已被限制在了 10M 左右。如果你的内网环境过于复杂例如经过了多次 NAT 转换那么请不要使用 清华大学(TUNA) 镜像站,容易被阻断

配置 Centos 网络yum源

请注意,CentOS 8(非 Stream 版)已提前进入 EOL 停止服务阶段,因此镜像已被官方移动。如果正在寻找关于这些系统的镜像,请配置各大镜像站的 centos-vault源。

注意:与之前的版本不同,CentOS 8 系统有两个yum 源:BaseOS和AppStream ,需要分别设置两个仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# centos 7
[root@centos7 ~]# vim /etc/yum.repos.d/base.repo
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7

[centosplus]
name=centosplus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
https://mirrors.aliyun.com/centos/7/centosplus/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

[updates]
name=updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#centos 8
[root@centos8 ~]# vim /etc/yum.repos.d/base.repo
cat > /etc/yum.repos.d/base.repo <<EOF
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
=https://mirror.nju.edu.cn/centos-vault/centos/$releasever/AppStream/$basearch/os/
gpgcheck=0
enabled=1

[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
=https://mirror.nju.edu.cn/centos-vault/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=0
enabled=1

[epel]
name=EPEL
baseurl=http://mirrors.aliyun.com/epel/$releasever/Everything/$basearch
http://mirrors.huaweicloud.com/epel/$releasever/Everything/$basearch
gpgcheck=0
enabled=1

[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
gpgcheck=0
enabled=1

centos 7 脚本配置网络yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
vim repoconfig.sh
#!bin/bash
repo=/etc/yum.repos.d
mkdir -p /etc/yum.repos.d/back
mv $repo/*.repo $repo/back
cd $repo
cat > base.repo <<EOF
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7

[centosplus]
name=centosplus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
https://mirrors.aliyun.com/centos/7/centosplus/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[base]
name=base
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7

[updates]
name=updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
EOF
yum clean all #清理缓存
yum makecache #更新缓存

使用命令配置

1
2
3
4
5
6
7
8
9
10
11
# 清华源, 对于 CentOS 7
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

# 南京大学源, 对于 CentOS 8, 由于已经停止支持,所以需要配置centos过期源centos-vault
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirror.nju.edu.cn/centos-vault/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

过期的yum源

需要确定所需要的小版本,如无特殊需要则使用该大版本的最后一个小版本,比如 6.10,5.11,需要在命令中替换$minorver变量。

清华CentOS Vault 软件仓库

centos-vault | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# CentOS 6 及之前
minorver=6.10
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$minorver|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

# CentOS 8 之后
minorver=8.5.2111
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$minorver|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

yum makecache # 更新软件包缓存

阿里云CentOS Vault 软件仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#  Centos 6
minorver=6.10
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

# CentOS 8
minorver=8.5.2111
sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo

yum makecache # 更新软件包缓存

手动配置 Ubuntu 网络软件源

Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用选择的软件源镜像。

清华源: ubuntu | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

阿里云源: ubuntu镜像_ubuntu下载地址_ubuntu安装教程-阿里巴巴开源镜像站 (aliyun.com)

南京大学源: Ubuntu 软件仓库镜像使用帮助 - MirrorZ Help (nju.edu.cn)

Ubuntu 版本:18.04 LTS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 备份原来的源,将以前的源备份一下,以防以后可以用的。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 打开/etc/apt/sources.list文件, 在前面添加如下条目,并保存。
sudo vim /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

# 更新源
sudo apt-get update
#如出现依赖问题,解决方式如下:
sudo apt-get -f install

#更新软件:
sudo apt-get upgrade

Ubuntu 版本:20.04 LTS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 备份原来的源,将以前的源备份一下,以防以后可以用的。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 打开/etc/apt/sources.list文件, 在前面添加如下条目,并保存。
sudo vim /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

Ubuntu 版本:22.04 LTS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 备份原来的源,将以前的源备份一下,以防以后可以用的。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 打开/etc/apt/sources.list文件, 在前面添加如下条目,并保存。
sudo vim /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

deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

LinuxMirrors 项目

GNU/Linux 一键更换系统软件源脚本

这是一个完全开源的非盈利项目,旨在为从事计算机相关行业的朋友们提供便利

Github: https://github.com/SuperManito/LinuxMirrors

Website: https://linuxmirrors.cn

适配系统及其版本

Debian 8.0 ~ 12
Ubuntu 14.04 ~ 23
Kali Linux 2.0 ~ 2023
Red Hat Enterprise Linux 7.0 ~ 9
Fedora 30 ~ 38
CentOS 7.0 ~ 8.5 / Stream 8 ~ 9
Rocky Linux 8 ~ 9
AlmaLinux 8 ~ 9
OpenCloudOS 8.6 / 9.0
openEuler 21.03 ~ 23
openSUSE Leep 15 / Tumbleweed
Arch Linux all

当前支持上述基于 Debian、RedHat、OpenCloudOS、openEuler、openSUSE、Arch Linux 的发行版和及其部分衍生版本
点击列表中的图标可快速前往其官网,理论支持所有架构的环境

脚本文件:

ChangeMirrors.sh