目录
1. 概述
2. 使用包管理系统的优势
3. 常见包管理器
3.1. APT
3.2. YUM
3.3. DNF
3.4. Zypper
3.5. Pacman
3.6. Portage
3.7. Slackware Package Management
4. RPM
4.1. 查询已安装软件包
4.2. 查看包依赖关系
4.3. 查询文件属于的软件包
4.4. 列出软件包中的文件
4.5. 查看软件描述信息
4.6. 安装
4.7. 卸载
4.8. 升级
5. YUM
5.1. 显示已经安装过的包
5.2. 显示可安装的包
5.3. 列出已配置的软件仓库
5.4. 添加仓库
5.5. 安装
5.6. 卸载
5.7. 升级
1. 概述
On Linux, software is typically built as a package, distributed through repositories, and managed on the end-user’s system through package managers. Each Linux system typically contains thousands of packages, many of which are required dependencies for other packages.
2. 使用包管理系统的优势
3. 常见包管理器
There are lots of package managers in Linux, each working a bit differently. Here is a list of common package managers, along with their supported distributions, package file formats, and a description.
3.1. APT
Using APT to Manage Packages in Debian and Ubuntu
Advanced Package Tool, more commonly known as APT, is a package management system for Debian, Ubuntu, and other similar Linux distributions. It acts as a front-end to the lower-level dpkg package manager, which is used for installing, managing, and providing information on .deb packages. Most distributions that use APT also include a collection of command-line tools that can be used to interface with APT. These tools include apt-get, apt-cache, and the newer apt, which essentially combines both of the previous tools with some modified functionality.
3.2. YUM
Using YUM to Manage Packages in CentOS/RHEL 7 and Earlier
Yellowdog Updater, Modified, more commonly known as YUM, is a package management tool for a variety of older RHEL-based distributions (such as CentOS 7) and older versions of Fedora. It provides an easy-to-use interface on top of the low-level functions available in the RPM Package Manger (RPM). It has largely been replaced by it successor Dandified YUM, also called DNF, on most newer RPM-based distributions.
3.3. DNF
Using DNF to Manage Packages in CentOS/RHEL 8 and Fedora
Dandified YUM, or simply DNF, is the successor to YUM. Just like YUM, DNF provides a user-friendly interface to the RPM Package Manager (RPM) that comes with CentOS, RHEL, Fedora, and many other Linux distributions. As the successor to YUM, DNF has several enhancements including increased performance, faster dependency resolution, and more complete documentation for its API. Most distributions still link the yum command to the DNF software and, since DNF maintains compatibility with much of YUM’s CLI, most commands using yum still function as intended.
3.4. Zypper
Zypper is the CLI tool used for managing packages on openSUSE Linux distributions. Just like DNF and YUM, packages are stored in the .rpm file format, though Zypper interfaces with the ZYpp (libzypp) library instead of RPM. Some users report that Zypper is faster than other package mangers and, unlike many others, has the ability to add repositories directly from its own CLI. See the Zypper manual for more usage details.
3.5. Pacman
Using Pacman to Manage Packages in Arch
Arch Linux and other similar distributions (like the popular Manjaro desktop distro) use the pacman package manager. Packages are stored as compressed tarballs and, as such, are generally smaller than other package formats. Pacman is unique in that it comes with a system to build packages, not just manage them. This system is called the ABS (Arch Build System).
3.6. Portage
Using Portage to Manage Packages in Gentoo
Portage, the package manager for Gentoo, is quite a bit different than other solutions. Instead of using pre-compiled binary packages, Portage packages are typically shell scripts called ebuilds. The emerge CLI tool can run these shell scripts to install packages, and is also responsible for managing dependencies and a database of installed packages.
3.7. Slackware Package Management
Managing Packages in Slackware
Slackware comes bundled with a few package management tools. The pkgtool is a TUI (menu-driven text interface) for managing packages and installing local packages. To install packages located on the internet, the slackpkg tool can be used. For more advanced tasks, use specialized tools like installpkg, upgradepkg, and removepkg.
4. RPM
RPM 命名 “RedHat Package Manager”,简称则为 RPM。这个机制最早由 Red Hat 这家公司开发出来的,后来实在很好用,因此很多 distributons 就使用这个机制来作为软件安装的管理方式,包括 Fedora,CentOS,SuSE 等知名的开发商都是用它。
4.1. 查询已安装软件包
rpm -qa | grep jdk
4.2. 查看包依赖关系
rpm -qpR jdk-11.0.12_linux-x64_bin.rpm
4.3. 查询文件属于的软件包
rpm -qf /usr/java/
4.4. 列出软件包中的文件
rpm -qpl jdk-11.0.12_linux-x64_bin.rpm
rpm -ql hdparm
4.5. 查看软件描述信息
rpm -qpi jdk-11.0.12_linux-x64_bin.rpm
rpm -qi hdparm
4.6. 安装
rpm -ivh jdk-11.0.12_linux-x64_bin.rpm
4.7. 卸载
rpm -e jdk-11.0.12-11.0.12-ga.x86_64
4.8. 升级
rpm -Uvh jdk-11.0.12_linux-x64_bin.rpm
5. YUM
Yum (Yellow dog Updater, Modified) 是一个基于 RPM 包管理的字符前端软件包管理器,能够从指定的服务器自动下载 RPM 包并且安装,可以自动解决处理包依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装,更方便的添加/删除/更新RPM包,便于管理系统的更新问题。被Yellow Dog Linux本身,以及Fedora、Red Hat Enterprise Linux采用。
5.1. 显示已经安装过的包
yum list installed | grep jdk
5.2. 显示可安装的包
yum list | grep jdk
5.3. 列出已配置的软件仓库
yum repolist
5.4. 添加仓库
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
5.5. 安装
yum install docker-ce docker-ce-cli containerd.io
5.6. 卸载
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
5.7. 升级
yum update tomcat
参考:
An Overview of Package Management in Linux: https://www.linode.com/docs/guides/linux-package-management-overview/ Linux Jargon Buster: What is a Package Manager in Linux? How Does it Work?: https://itsfoss.com/package-manager/