前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【CentOS】:软件包管理

【CentOS】:软件包管理

作者头像
WEBJ2EE
发布2021-09-02 15:40:53
1.3K0
发布2021-09-02 15:40:53
举报
文章被收录于专栏:WebJ2EEWebJ2EE
代码语言:javascript
复制
目录
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.

  • Packages
    • Most software applications designed for Linux or Unix systems are distributed as packages, which are archives that contain the pre-compiled binary software files, installation scripts, configuration files, dependency requirements, and other details about the software. These packages are typically specific to a particular distribution and formatted in that distribution’s preferred package format, such as .deb for Debian/Ubuntu and .rpm for CentOS/RHEL.
    • While it’s relatively simple for a user to install a package file, there are other complexities to consider. These complexities include obtaining (downloading) the package, ensuring packages are upgraded with security and bug fixes, and maintaining all the dependencies for the software.
  • Repositories
    • While a user can obtain package files through any method of file transfer, it is typical to use software repositories (also called repos) to obtain packages. Repositories are simply the location where the packages are stored, commonly accessible via the internet. A repository can contain a single package or thousands of packages. Most Linux distributions have their own unique repositories, sometimes separating out their cores packages into one while additional features are in others.
  • Dependencies
    • Its very common in almost any operating system for software to require other software to run. In Linux, each package contains metadata detailing the additional packages that are required. These additional packages are called dependencies. A single package can sometimes have hundreds of dependencies. When installing, upgrading, or removing packages, these dependencies may also need to installed, upgraded, and optionally removed.
  • Package Managers
    • A package manager reduces the complexity for the end-user by automating the process of obtaining, installing, upgrading, and removing packages and their dependencies. This dramatically improves the user experience and the ability to properly and efficiently manage the software on your Linux system. Today, package managers can be a defining feature for Linux distributions and many system administrators prefer to use a particular distribution based on its package management system (among other considerations).

2. 使用包管理系统的优势

  • Easily obtain the correct, trusted, and stable package for your Linux distribution. Since most distributions maintain their own repositories, using a package manager can ensure you only install packages that have been thoroughly vetted, are stable, are trusted, and work with your system. The subjective judgments and community standards that guide package management also guide the “feel” and “stability” of a given system.
  • Automatically manage all dependencies when taking action on a package. While dependencies can be distributed inside the original package to ensure the correct versions of the required software are always present, this increases disk usage and package file size. In most cases, package managers will manage dependencies as separate packages, allowing them to be shared with other software and reducing disk usage and file size.
  • Follow the unique conventions for each Linux distribution. Linux distributions often have conventions for how applications are configured and stored in the /etc/ and /etc/init.d/ directories. By using packages, distributions are able to enforce a single standard.
  • Stay up-to-date on security patches and software updates. Most package managers provide a single command to automatically update all packages to the latest versions stored on the configured repositories. Provided those repositories are consistently maintained, this enables you to quickly get important security updates.

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

  • Distributions: Debian-based, including Debian and Ubuntu
  • Commands: apt, apt-get, apt-cache
  • Underlying package management tool: dpkg
  • Package file format: .deb

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

  • Distributions: RHEL/CentOS 7, Fedora 21, and earlier versions of both distributions
  • Command: yum
  • Underlying package management tool: RPM (RPM Package Manager)
  • Package file format: .rpm

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

  • Distributions: RHEL/CentOS 8, Fedora 22, and later versions of both distributions
  • Commands: dnf, yum
  • Underlying package management tool: RPM (RPM Package Manager)
  • Package file format: .rpm

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

  • Distributions: openSUSE
  • Command: zypper
  • Underlying package management tool: ZYpp (also called libzypp)
  • Package file format: .rpm

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

  • Distributions: Arch-based, including Arch and Manjaro
  • Command: pacman
  • Package file format: .tar.xz (and other compressed tar formats)

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

  • Distributions: Gentoo
  • Command: emerge
  • Package file format: ebuild shell script or .tbz2 (compressed tar archive)

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

  • Distributions: Slackware
  • Commands: slackpkg, pkgtool, installpkg, upgradepkg, removepkg
  • Package file format: .tgz and .txz (compressed tar archive)

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. 查询已安装软件包

代码语言:javascript
复制
rpm -qa | grep jdk
  • q=query
  • a=all
  • grep=过滤

4.2. 查看包依赖关系

代码语言:javascript
复制
rpm -qpR jdk-11.0.12_linux-x64_bin.rpm

4.3. 查询文件属于的软件包

代码语言:javascript
复制
rpm -qf /usr/java/

4.4. 列出软件包中的文件

代码语言:javascript
复制
rpm -qpl jdk-11.0.12_linux-x64_bin.rpm
rpm -ql hdparm

4.5. 查看软件描述信息

代码语言:javascript
复制
rpm -qpi jdk-11.0.12_linux-x64_bin.rpm
rpm -qi hdparm

4.6. 安装

代码语言:javascript
复制
rpm -ivh jdk-11.0.12_linux-x64_bin.rpm
  • i=install 安装
  • v=verbose 提示
  • h=hash 进度条

4.7. 卸载

代码语言:javascript
复制
rpm -e jdk-11.0.12-11.0.12-ga.x86_64

4.8. 升级

代码语言:javascript
复制
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. 显示已经安装过的包

代码语言:javascript
复制
yum list installed | grep jdk

5.2. 显示可安装的包

代码语言:javascript
复制
yum list | grep jdk

5.3. 列出已配置的软件仓库

代码语言:javascript
复制
yum repolist

5.4. 添加仓库

代码语言:javascript
复制
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

5.5. 安装

代码语言:javascript
复制
yum install docker-ce docker-ce-cli containerd.io

5.6. 卸载

代码语言:javascript
复制
yum remove docker \
           docker-client \
           docker-client-latest \
           docker-common \
           docker-latest \
           docker-latest-logrotate \
           docker-logrotate \
           docker-engine

5.7. 升级

代码语言:javascript
复制
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/


本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-08-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 WebJ2EE 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档