软件包管理
RHEL/CentOS
Debian/Ubuntu
镜像源
Ubuntu
22.04
阿里云:
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse清华:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
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
# 预发布软件源,建议保持注释状态
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse=====
apt
Snap和APT是Ubuntu Linux操作系统中的两种软件包管理系统,它们有一些区别。
- 软件包格式:Snap(全称:Snappy)使用的是一种基于容器技术的软件包格式,其中包含了应用程序及其依赖的所有文件和库。这种打包方式使得Snap能够在不同的Linux发行版上运行,并且可以提供更好的应用程序隔离性和安全性。APT(Advanced Package Tool)使用的是.deb软件包格式,它通常只包含应用程序本身及其核心依赖,其他依赖项则会通过系统的软件包管理器进行安装。
- 软件源:APT使用系统的软件源来管理软件包的分发和更新。用户需要配置适当的软件源,并使用命令行或图形界面工具来更新软件包。Snap则具有独立的软件商店(Snap Store)作为软件源,用户可以直接在Snap Store中搜索、安装和更新应用程序。
- 版本控制:APT通常维护软件包的不同版本,并允许用户选择特定的软件包版本进行安装。Snap则采用滚动更新模式,它会自动将应用程序更新到最新版本,不提供选择特定版本的选项。这使得Snap能够提供最新的软件功能和安全修复,但有时也可能导致不稳定或不兼容的情况。
- 应用程序隔离性:由于Snap使用容器技术,它能够提供更好的应用程序隔离性。每个Snap应用程序都运行在独立的沙箱环境中,与主系统和其他应用程序相互隔离,这可以增加系统的安全性和稳定性。APT则将软件包的文件和库直接安装到系统的共享目录中,应用程序之间的隔离性较低。
总体而言,Snap适用于那些需要较高安全性和独立性的应用程序,它提供了更容易的安装和更新流程。而APT则更适合传统的软件包管理方式,更灵活地控制特定软件包的版本和依赖关系。用户可以根据具体需求选择使用Snap还是APT来管理其Ubuntu系统中的软件包。
apt 相关命令说明
#更新apt仓库
apt-get update
#搜索软件
apt-cache search package_name
#查看apt仓库中软件包的版本有哪些,必要的时候需要 apt update 来更新仓库
apt-cache madison package-name
#指定版本安装,
apt-cache madison package-name
apt-get install package_name=version
#查看deb包中包含的文件
dpkg -c package-name.deb
#查看apt安装的程序包含的文件,等同于centos的rpm -ql
dpkg -L ntpdate
#查看软件包信息
apt-cache show package_name
#查看软件包依赖关系
apt-cache show depends package_name
#查看每个软件包的简要信息
apt-cache dump
#查看文件来自哪个包
dpkg -S `which python3.8`
#查看命令来自哪个包???
#方法一
apt -y install apt-file #需要先安装apt-file包
apt-file update #更新软件库(大约需要下载300M)
apt-file search `which cmd` #通过命令的绝对路径搜索
#方法二
apt -y install aptitude #需要先安装aptitude包
aptitude search ping查看所有安装的包
要查看在Linux系统中已安装的所有软件包,你可以使用以下命令:
apt list --installed
这将列出所有已安装的软件包及其版本。请注意,这可能会生成一长串输出,你可以使用管道符(|)和less命令来逐页查看:
apt list --installed | less
你也可以使用grep来搜索特定的包,例如:
apt list --installed | grep <包名称>
替换<包名称>为你想要查找的实际软件包的名称。
# 所有已安装和可安装的包
apt list
apt 仓库详解
仓库文件存放位置:
- 相当于centos中的yum仓库 /etc/yum.repo.d/*
/etc/apt/sources.list #官方自带源文件,一般需要替换成企业内部或国内的镜像地址
/etc/apt/sources.list.d/* #扩展源路径,如zabbix、docker等仓库文件内容:
# cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse档案类型
每行的第一个单词deb或deb-src指示归档的类型 (Archive type):
- deb表示归档文件包含二进制软件包(deb), 也就是我们通常使用的预编译软件包
- deb-src指示源软件包,它是程序的源码以和Debian控制文件(.dsc)以及文件diff.gz。文件diff.gz包含了打包程序所需的更改
RUL
每行的第二个条目是软件包仓库的URL,apt用它来下载软件。可以更换仓库地址为其他地理位置更靠近自己的镜像来提高下载速度。
发行版本 (Distribution)
“发行版"可以分别是:
- 发行版代号或别名
- focal
- 发行版类
- security、updates、proposed、backports
软件包分类 (Component)
跟在发行版之后的就是软件包的具体分类了,可以有一个或多个
- main 完全的自由软件。这些软件包被视为 Debian 发型版的一部分
- restricted 不完全的自由软件。
- universe ubuntu官方不提供支持与补丁,全靠社区支持。
- muitiverse 非自由软件,完全不提供支持和补丁。
需要哪些分类,就把分类写道发行版本后面,在我的树莓派上的source.list上,就表明了开源和不开源的软件包都需要, 并且还多了rpi分类的软件包
apt 垃圾清理
在使用 apt-get remove 命令卸载软件包之后,可能会留下一些相关的多余文件,包括配置文件、数据、依赖和缓存等。你可以使用以下命令来清理这些多余的文件:
-
清理多余的依赖文件:
sudo apt-get autoremove这个命令会自动移除不再需要的依赖文件。需要注意的是,使用
autoremove命令时,请认真检查你将要删除的依赖文件列表,确保不会意外移除必需的包。 -
清理缓存:
sudo apt-get clean这个命令会清除本地缓存中的已安装软件包,释放一些磁盘空间。
-
清理配置文件:
sudo apt-get purge [package-name]这个命令会卸载软件包,并清除所有与之相关的配置文件。
如果你只想清除特定的配置文件,可以使用
rm命令手动删除它们。
以上命令都需要使用 sudo 权限来执行。如果你需要更详细的信息和选项,请参考相关命令的帮助文档。
apt 故障排查
...
Ign:4 https://mirrors.aliyun.com/ubuntu bionic-backports InRelease
Err:5 https://mirrors.aliyun.com/ubuntu bionic Release
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 157.119.175.224 443]
Err:6 https://mirrors.aliyun.com/ubuntu bionic-security Release
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 157.119.175.224 443]
Err:7 https://mirrors.aliyun.com/ubuntu bionic-updates Release
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 157.119.175.224 443]
Err:8 https://mirrors.aliyun.com/ubuntu bionic-backports Release
Certificate verification failed: The certificate is NOT trusted. The certificate issuer is unknown. Could not handshake: Error in the certificate verification. [IP: 157.119.175.224 443]
Reading package lists...
W: https://mirrors.aliyun.com/ubuntu/dists/bionic/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu/dists/bionic-security/InRelease: No system certificates available. Try installing ca-certificates.
W: https://mirrors.aliyun.com/ubuntu/dists/bionic-updates/InRelease: No system certificates available. Try installing ca-certificates.
...
使用官方的Ubuntu1804基础镜像构建时,出现以上报错应该如何解决,我将apt源指向了阿里云后就出现了此报错
根据您提供的信息,问题出现在使用阿里云作为APT源时的证书验证失败。这可能是由于缺少系统的根证书或根证书不正确导致的。
要解决这个问题,您可以尝试以下步骤:
- 首先,确保您的系统上已经安装了
ca-certificates包。您可以使用以下命令安装它:
sudo apt-get update
sudo apt-get install ca-certificates
- 安装
ca-certificates后,尝试清除现有的APT缓存,并重新加载软件包列表:
sudo rm -rf /var/lib/apt/lists/*
sudo apt-get update
- 如果上述步骤没有解决问题,您可以尝试更新系统的根证书。在Ubuntu上,根证书存储在
/usr/local/share/ca-certificates/目录中。您可以尝试手动更新证书存储:
sudo cp /etc/ssl/certs/ca-certificates.crt /usr/local/share/ca-certificates/ca-certificates.crt
sudo update-ca-certificates
- 如果问题仍然存在,您可以尝试更换其他可信任的APT源。您可以编辑
/etc/apt/sources.list文件,将阿里云的源替换为官方的Ubuntu源,然后再次运行sudo apt-get update进行测试。
请注意,阿里云的APT源可能存在问题,或者您的网络环境可能对连接到阿里云的服务器有限制。在尝试以上解决方案之前,确保您的网络连接正常,并且其他软件源可以正常访问。
snap
Snap是一种软件打包和分发格式,它使开发人员能够将应用程序及其依赖打包成一个独立的、可移植的软件包。以下是使用Snap的详细步骤:
-
安装Snap:如果你的Ubuntu系统上没有安装Snap,可以使用以下命令进行安装:
sudo apt install snapd -
搜索可用的Snap应用程序:使用以下命令在Snap Store中搜索可用的Snap应用程序:
snap find <关键词> -
安装Snap应用程序:使用以下命令来安装Snap应用程序:
sudo snap install <应用程序名称> -
查看已安装的Snap应用程序:使用以下命令来查看已安装的Snap应用程序:
snap list -
卸载Snap应用程序:使用以下命令来卸载Snap应用程序:
sudo snap remove <应用程序名称> -
更新Snap应用程序:Snap应用程序会自动更新到最新版本,但你也可以手动检查更新并应用它们。使用以下命令来检查更新:
sudo snap refresh -
Snap配置和管理:Snap还提供了一些配置和管理选项。例如,你可以使用以下命令来查看Snap的配置信息:
snap info <应用程序名称>你还可以使用以下命令来管理Snap的权限:
phpCopy codesnap connections <应用程序名称> snap connect <应用程序名称>:<接口>:<插槽> snap disconnect <应用程序名称>:<接口> -
Snap文档和帮助:你可以使用以下命令来查找Snap的文档和帮助信息:
snap help
这些是使用Snap的基本命令和步骤。Snap提供了更简单的应用程序安装和更新过程,并提供了更好的应用程序隔离性和安全性。你可以根据需要探索更多Snap的功能和选项。