更換 Ubuntu 系統(tǒng) apt 命令安裝軟件源
清華大學(xué)開源軟件鏡像站
https://mirrors.tuna.tsinghua.edu.cn/
1. Ubuntu 的軟件源配置文件 /etc/apt/sources.list
MIRRORS -> 使用幫助 -> ubuntu
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
Ubuntu 系統(tǒng) apt 命令安裝軟件默認(rèn)源為國外源 (服務(wù)器位于國外),在國內(nèi)使用速度較慢,建議改為國內(nèi)的鏡像源服務(wù)器。
Ubuntu 的軟件源配置文件 /etc/apt/sources.list
yongqiang@yongqiang:~$ cat /etc/apt/sources.list
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu/ focal main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ focal-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://archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal universe
deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ focal-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://archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal multiverse
deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-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://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner
deb http://security.ubuntu.com/ubuntu/ focal-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted
deb http://security.ubuntu.com/ubuntu/ focal-security universe
# deb-src http://security.ubuntu.com/ubuntu/ focal-security universe
deb http://security.ubuntu.com/ubuntu/ focal-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ focal-security multiverse
yongqiang@yongqiang:~$
備份軟件安裝源配置文件,以防更換的軟件源無法使用,可以使用備份文件再恢復(fù)到原來的鏡像源地址。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
yongqiang@yongqiang:~$ lsb_release -c
Codename: focal
yongqiang@yongqiang:~$
yongqiang@yongqiang:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
yongqiang@yongqiang:~$
yongqiang@yongqiang:~$ lsb_release -a | grep Codename | awk '{print $2}'
No LSB modules are available.
focal
yongqiang@yongqiang:~$
yongqiang@yongqiang:~$ cat /etc/issue
Ubuntu 20.04.3 LTS \n \l
yongqiang@yongqiang:~$
yongqiang@yongqiang:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
yongqiang@yongqiang:~$
2. 清華大學(xué)開源軟件鏡像站 - Ubuntu 鏡像
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
本鏡像僅包含 32/64 位 x86 架構(gòu)處理器的軟件包,在 ARM (arm64, armhf)、PowerPC (ppc64el)、RISC-V (riscv64) 和 S390x 等架構(gòu)的設(shè)備上 (對(duì)應(yīng)官方源為 ports.ubuntu.com) 請(qǐng)使用 ubuntu-ports 鏡像。
2.1. 手動(dòng)替換
Ubuntu 的軟件源配置文件是 /etc/apt/sources.list
。將系統(tǒng)自帶的該文件備份,在該文件末尾添加下面的內(nèi)容,即可使用 TUNA 的軟件源鏡像。
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
更換軟件安裝源
sudo vim /etc/apt/sources.list
選擇你的 ubuntu 版本: 20.04 LTS
# 默認(rèn)注釋了源碼鏡像以提高 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
# 預(yù)發(fā)布軟件源,不建議啟用
# 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
因鏡像站同步有延遲,可能會(huì)導(dǎo)致生產(chǎn)環(huán)境系統(tǒng)不能及時(shí)檢查、安裝上最新的安全更新,不建議替換 security 源。
2.2. 命令替換
執(zhí)行如下命令自動(dòng)替換
sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
更新軟件列表:
sudo apt-get update --yes
sudo apt update --yes
更新軟件:
sudo apt-get upgrade --yes
sudo apt upgrade --yes
3. Certificate verification failed: The certificate is NOT trusted.
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification.
3.1. 更新證書 ca-certificates (建議)
- 編輯
/etc/apt/sources.list
文件,臨時(shí)將 https 源修改為 http 源。 - 更新證書 ca-certificates
sudo apt install ca-certificates
sudo apt-get install --reinstall ca-certificates
sudo apt install apt-transport-https ca-certificates
sudo apt-get update
- 編輯
/etc/apt/sources.list
文件,將 http 源修改回 https 源。
3.2. https 源修改為 http 源
編輯 /etc/apt/sources.list
文件,將 Ubuntu 對(duì)應(yīng)版本的軟件源里的 https
替換成 http
,https
是加密傳輸,需要證書認(rèn)證。去掉 s
,將 https
源修改為 http
源。文章來源:http://www.zghlxwxcb.cn/news/detail-737659.html
References
https://yongqiang.blog.csdn.net/
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/文章來源地址http://www.zghlxwxcb.cn/news/detail-737659.html
到了這里,關(guān)于更換 Ubuntu 系統(tǒng) apt 命令安裝軟件源的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!