首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

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

  • 24-03-18 03:09
  • 3146
  • 9850
blog.csdn.net

更换 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:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

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

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  • 1
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:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

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
  • 1

更换软件安装源

sudo vim /etc/apt/sources.list
  • 1

选择你的 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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

因镜像站同步有延迟,可能会导致生产环境系统不能及时检查、安装上最新的安全更新,不建议替换 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
  • 1
  • 2

更新软件列表:

sudo apt-get update --yes
sudo apt update --yes
  • 1
  • 2

更新软件:

sudo apt-get upgrade --yes
sudo apt upgrade --yes
  • 1
  • 2

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.
  • 1

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
  • 2
  • 3
  • 4
  • 5
  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/

注:本文转载自blog.csdn.net的Yongqiang Cheng的文章"https://blog.csdn.net/chengyq116/article/details/129074261"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

120
运维
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top