Ubuntu ARMv8/AArch64 一条命令设置国内源
flyfish
假定安装的版本是
64-bit ARM (ARMv8/AArch64) server install image
版本是22.04
备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
查看原来使用的哪个源
sudo apt nano /etc/apt/sources.list
也可以在这里直接编辑
假如使用的镜像是 http://ports.ubuntu.com/ubuntu-ports/
一条命令
sudo sed -i 's|http://ports.ubuntu.com/ubuntu-ports/|http://repo.huaweicloud.com/ubuntu-ports/|g' /etc/apt/sources.list && sudo apt update
在 sed
命令中,s
和 g
是两个重要的选项,它们分别表示不同的功能:
-
s
(substitute):s
是sed
中最常用的命令之一,表示“替换”。- 其基本语法是
s/pattern/replacement/flags
,其中:pattern
是要匹配的模式(通常是正则表达式)。replacement
是替换后的文本。flags
是可选的标志,用于控制替换行为。
-
g
(global):g
是一个标志,表示“全局替换”。- 默认情况下,
sed
只会替换每一行中第一个匹配到的模式。如果加上g
标志,sed
会替换每一行中所有匹配到的模式
命令说明
-
s|http://ports.ubuntu.com/ubuntu-ports/|http://repo.huaweicloud.com/ubuntu-ports/|g
:s
表示替换操作。http://ports.ubuntu.com/ubuntu-ports/
是要匹配的模式。http://repo.huaweicloud.com/ubuntu-ports/
是替换后的文本。g
表示全局替换,即在同一行中如果有多个http://ports.ubuntu.com/ubuntu-ports/
,都会被替换为http://repo.huaweicloud.com/ubuntu-ports/
。
-
-i
选项表示直接在文件中进行修改,而不是输出到标准输出。 -
&& sudo apt update
表示在sed
命令成功执行后,运行apt update
命令来更新软件包列表。
原来是
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ jammy universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy universe
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-updates universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ports.ubuntu.com/ubuntu-ports/ jammy multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-updates multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security universe
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security multiverse
更改后,为了看的清楚些,删除注释
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy main restricted
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-updates main restricted
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy universe
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-updates universe
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy multiverse
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-updates multiverse
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-security main restricted
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-security universe
deb http://repo.huaweicloud.com/ubuntu-ports/ jammy-security multiverse