打开centos Stream 9
进入终端输入 cd /etc/yum.repos.d
输入命令 vim update_mirror.pl
进入vim编辑模式,输入i 插入文本
把下面文本复制粘贴到虚拟机创建update_mirror.pl的文件中
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
my $mirrors = 'https://mirrors.tuna.tsinghua.edu.cn/centos-stream';
if (@ARGV < 1) {
die "Usage: $0 <filename1> <filename2> ...\n";
}
while (my $filename = shift @ARGV) {
my $backup_filename = $filename . '.bak';
rename $filename, $backup_filename;
open my $input, "<", $backup_filename;
open my $output, ">", $filename;
while (<$input>) {
s/^metalink/# metalink/;
if (m/^name/) {
my (undef, $repo, $arch) = split /-/;
$repo =~ s/^\s+|\s+$//g;
($arch = defined $arch ? lc($arch) : '') =~ s/^\s+|\s+$//g;
if ($repo =~ /^Extras/) {
$_ .= "baseurl=${mirrors}/SIGs/\$releasever-stream/extras" . ($arch eq 'source' ? "/${arch}/" : "/\$basearch/") . "extras-common\n";
} else {
$_ .= "baseurl=${mirrors}/\$releasever-stream/$repo" . ($arch eq 'source' ? "/" : "/\$basearch/") . ($arch ne '' ? "${arch}/tree/" : "os") . "\n";
}
}
print $output $_;
}
}
粘贴好后按一下键盘上右上角的Esc退出编辑模式
在按Shift+:进入末行模式输入wq保存退出
回到终端输入:dnf install perl
回车
等待
输入y回车
在次输入y回车
显示完毕后在输入yum clean all && yum makecache
后在输入yum clean all && yum makecache
显示元数据缓存已建立就换源成功了