操作指南
using apt source with sed replacing (recomended)
# su [options] [-] [<user> [<argument>...]]
# su - $USER
o=http://security.ubuntu.com/ubuntu/
n=https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
sed -i "s,$o,$n,g" /etc/apt/sources.list
o=http://archive.ubuntu.com/ubuntu/
sed -i "s,$o,$n,g" /etc/apt/sources.list
# update - update list of available packages
apt update
# upgrade - upgrade the system by installing/upgrading packages
apt upgrade
you also can use other source :
- 清华源
https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ - 阿里源
http://mirrors.aliyun.com/ubuntu/ - 中科大源
https://mirrors.ustc.edu.cn/ubuntu/ - 网易源
http://mirrors.163.com/ubuntu/
or you can use replace.sh script
# only download replace.sh file
# curl -O https://ghproxy.com/https://raw.githubusercontent.com/ymc-github/use-apt-src/main/replace.sh
# get replace.sh script usage
./replace.sh -h
# get replace.sh script version
# ./replace.sh -v
# zero:task:s:swicth-user
# if you do not have the rights to edit file /etc/apt/sources.list
# you can swicth user with su.
# su [options] [-] [<user> [<argument>...]]
# su - $USER
# zero:task:e:swicth-user
# use some source in china
./replace.sh tsqinghua
./replace.sh aliyun
./replace.sh 163
# use offical source
./replace.sh ubuntu
# or
# curl -sfL https://ghproxy.com/https://raw.githubusercontent.com/ymc-github/use-apt-src/main/replace.sh | sh
using /etc/apt/sources.list backup files
some code snippet
# zero:task:s:add-apt-qinghua-source
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
file=/etc/apt/sources.list
# or use file
# file=/etc/apt/sources.list.d/qinghua_ubuntu2204.list
sudo cat <<EOF >$file
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
EOF
sudo apt update
sudo apt upgrade
# zero:task:e:add-apt-qinghua-source
you can use backup shell script :
GC_PROXY="https://ghproxy.com/"
GC_URL="https://github.com/YMC-GitHub/use-apt-src"
GC_URL="${GC_PROXY}${GC_URL}"
git clone -b main "$GC_URL"
# use-apt-src/index.sh -h
# get current using
use-apt-src/index.sh get 22.04 tsinghua
# download
use-apt-src/index.sh download 22.04 tsinghua
# use
use-apt-src/index.sh use 22.04 tsinghua
# del
use-apt-src/index.sh del 22.04 tsinghua
# add
use-apt-src/index.sh add 22.04 tsinghua