0


更换 Ubuntu 系统 apt 命令安装软件源

更换 Ubuntu 系统 apt 命令安装软件源

清华大学开源软件镜像站
https://mirrors.tuna.tsinghua.edu.cn/

1. Ubuntu 的软件源配置文件

/etc/apt/sources.list

MIRRORS -> 使用帮助 -> ubuntu
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

在这里插入图片描述

Ubuntu 系统 apt 命令安装软件默认源为国外源 (服务器位于国外),在国内使用速度较慢,建议改为国内的镜像源服务器。

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:~$

备份软件安装源配置文件,以防更换的软件源无法使用,可以使用备份文件再恢复到原来的镜像源地址。

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. 清华大学开源软件镜像站 - Ubuntu 镜像

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
本镜像仅包含 32/64 位 x86 架构处理器的软件包,在 ARM (arm64, armhf)、PowerPC (ppc64el)、RISC-V (riscv64) 和 S390x 等架构的设备上 (对应官方源为 ports.ubuntu.com) 请使用 ubuntu-ports 镜像。

2.1. 手动替换

Ubuntu 的软件源配置文件是

/etc/apt/sources.list

。将系统自带的该文件备份,在该文件末尾添加下面的内容,即可使用 TUNA 的软件源镜像。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

更换软件安装源

sudo vim /etc/apt/sources.list

选择你的 ubuntu 版本: 20.04 LTS

# 默认注释了源码镜像以提高 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 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

因镜像站同步有延迟,可能会导致生产环境系统不能及时检查、安装上最新的安全更新,不建议替换 security 源。

2.2. 命令替换

执行如下命令自动替换

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 (建议)

  1. 编辑 /etc/apt/sources.list 文件,临时将 https 源修改为 http 源。
  2. 更新证书 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
  1. 编辑 /etc/apt/sources.list 文件,将 http 源修改回 https 源。

3.2. https 源修改为 http 源

编辑

/etc/apt/sources.list

文件,将 Ubuntu 对应版本的软件源里的

https

替换成

http

https

是加密传输,需要证书认证。去掉

s

,将

https

源修改为

http

源。

References

https://yongqiang.blog.csdn.net/
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/


本文转载自: https://blog.csdn.net/chengyq116/article/details/129074261
版权归原作者 Yongqiang Cheng 所有, 如有侵权,请联系我们删除。

“更换 Ubuntu 系统 apt 命令安装软件源”的评论:

还没有评论