Ubuntu的apt-get源修改与使用及常用指令
Ubuntu的apt-get源修改与使用及常用指令

Ubuntu的apt-get源修改与使用及常用指令

新装的ubuntu。使用apt-get命令安装软件时,有时候速度比较慢,有时候会失败。因此考虑用国内的镜像源更换下apt-get的默认源。

一、修改apt-get源

# 更新源
sudo apt-get update
# 备份原文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 编辑源列表文件
sudo vim /etc/apt/sources.list
# 将原来的列表删除,添加如下内容(清华大学镜像源)

# start
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# end

# 更新源
sudo apt-get update

二、出现问题:

在执行sudo apt-get update后出现以下的问题:

lee@lee-virtual-machine:~/workspace/yolov5Pro/yolov5$ sudo apt-get update
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease [242 kB]
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease [88.7 kB]
Err:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease [83.3 kB]
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease [88.7 kB]
Err:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Err:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Err:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
Reading package lists... Done
W: GPG error: https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-updates InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-backports InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

解决办法:

更换源之后需要添加公钥,执行以下命令:

  • 注意:这里的recv-keys就是报错中的key,粘贴过来即可 3B4FE6ACC0B21F32

  • gpg --keyserver  keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
    gpg --export --armor 3B4FE6ACC0B21F32 | sudo apt-key add -
lee@lee-virtual-machine:~/workspace/yolov5Pro/yolov5$ gpg --keyserver  keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
gpg --export --armor 3B4FE6ACC0B21F32 | sudo apt-key add -
gpg: directory '/home/lee/.gnupg' created
gpg: keybox '/home/lee/.gnupg/pubring.kbx' created
gpg: /home/lee/.gnupg/trustdb.gpg: trustdb created
gpg: key 3B4FE6ACC0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

三、apt-get常用命令

apt-get使用于deb包管理式的操作系统,主要用于自动从互联网的软件仓库照中搜索、安装、升级、卸载软件或操作系统,需要root权限

sudo apt-get update 更新源

sudo apt-get install package 安装包

sudo apt-get remove package 删除包

sudo apt-cache search package 搜索软件包

sudo apt-cache show package 获取包的相关信息,如说明、大小、版本等

sudo apt-get install package --reinstall 重新安装包

sudo apt-get -f install 修复安装

sudo apt-get remove package --purge 删除包,包括配置文件等

sudo apt-get build-dep package 安装相关的编译环境

sudo apt-get upgrade 更新已安装的包

sudo apt-get dist-upgrade 升级系统

sudo apt-cache depends package 了解使用该包依赖那些包

sudo apt-cache rdepends package 查看该包被哪些包依赖

sudo apt-get source package 下载该包的源代码

sudo apt-get clean && sudo apt-get autoclean 清理无用的包

sudo apt-get check 检查是否有损坏的依赖

发表回复

您的电子邮箱地址不会被公开。