Home >System Tutorial >LINUX >Analyze the functions and characteristics of apt, yum, dnf and pkg

Analyze the functions and characteristics of apt, yum, dnf and pkg

WBOY
WBOYforward
2024-01-04 20:25:44672browse
Introduction Most modern Unix-like operating systems provide a centralized mechanism for searching and installing software. Software is usually stored in repositories and distributed through packages. The work of handling packages is called package management. Packages provide the basic components of an operating system, as well as shared libraries, applications, services, and documentation.

详解apt、yum、dnf 和 pkg

introduce

In addition to installing software, the package management system also provides tools to update installed packages. Package repositories help ensure that the code used in your system has been reviewed and that the installed version of the software has been approved by developers and package maintainers.

When configuring a server or development environment, it is best to understand the situation of packages outside the official repository. Packages in a distribution's stable version may be out of date, especially for new or rapidly evolving software. However, package management is a vital skill for both system administrators and developers, and packaged software is a huge asset to major Linux distributions.

This guide is designed to quickly introduce the basics of finding, installing, and upgrading packages on various Linux distributions, and to help you cross-reference these contents across multiple systems.

Package Management System: A Brief Overview

Most package systems are built around collections of package files. A package file is typically an archive file that contains compiled binaries and other resources for the software, as well as installation scripts. Package files also contain valuable metadata, including their dependencies and a list of other packages required to install and run them.

While the functionality and benefits of these package management systems are largely the same, packaging formats and tools vary by platform:

operating system Format tool
Debian .deb apt, apt-cache, apt-get, dpkg
Ubuntu .deb apt, apt-cache, apt-get, dpkg
CentOS .rpm yum
Fedora .rpm dnf
FreeBSD Ports, .txz make, pkg

Debian and its derivatives, such as Ubuntu, Linux Mint and Raspbian, their package format is .deb. APT This advanced package management tool provides commands for the most common operations: search repositories, install packages and their dependencies, and manage upgrades. In the local system, we can also use the dpkg program to install a single deb file. The APT command serves as the front end of the underlying dpkg, and sometimes it is also called directly.

Most recently released debian derivatives include the apt command, which provides a concise and unified interface for common operations usually handled by apt-get and apt-cache commands. This command is optional, but using it can simplify some tasks.

CentOS, Fedora and other members of the Red Hat family use RPM files. In CentOS, interact with individual package files and repositories via yum.

In recent Fedora versions, yum has been replaced by dnf, which is a modern branch of it that retains most of yum's interfaces.

FreeBSD’s binary package system is managed by the pkg command. FreeBSD also provides the Ports collection, which is a local directory structure and tool that allows users to use Makefile to compile and install packages directly from the source code after obtaining the source code.

Update package list

Most systems will have a local package database corresponding to the remote repository. It is best to update this database before installing or upgrading packages. In addition, yum and dnf will also automatically check for updates before performing some operations. Of course you can update the system at any time.

system Order
Debian / Ubuntu sudo apt-get update
sudo apt update
CentOS yum check-update
Fedora dnf check-update
FreeBSD Packages sudo pkg update
FreeBSD Ports sudo portsnap fetch update
Update installed packages

Without a package system, it is a difficult task to ensure that all installed software on the machine is kept up to date. You will have to track upstream changes and security alerts for hundreds of different packages. While a package manager doesn't solve every problem you encounter when upgrading software, it does enable you to use some commands to maintain most system components.

On FreeBSD, upgrading installed ports may introduce breaking changes, and some steps require manual configuration, so it is best to read the contents of /usr/ports/UPDATING before updating via portmaster.

system Order illustrate
Debian / Ubuntu sudo apt-get upgrade Only update installed packages
sudo apt-get dist-upgrade Packages may be added or removed to satisfy new dependencies
sudo apt upgrade Similar to apt-get upgrade
sudo apt full-upgrade Similar to apt-get dist-upgrade
CentOS sudo yum update
Fedora sudo dnf upgrade
FreeBSD Packages sudo pkg upgrade
FreeBSD Ports less /usr/ports/UPDATING Use less to view the update prompts of ports (use the up and down cursor keys to scroll and press q to exit).
cd /usr/ports/ports-mgmt/portmaster && sudo make install && sudo portmaster -a Install portmaster and then use it to update installed ports
Search for a package

Most distributions provide graphical or menu-driven tools for package collections. We can browse software by category, which is also a good way to discover new software. However, the fastest and most efficient way to find a package is to search using a command line tool.

system Order illustrate
Debian / Ubuntu apt-cache search search_string
apt search search_string
CentOS yum search search_string
yum search all search_string Search all fields, including description
Fedora dnf search search_string
dnf search all search_string Search all fields, including description
FreeBSD Packages pkg search search_string Search by name
pkg search -f search_string Search by name and return full description
pkg search -D search_string Search description
FreeBSD Ports cd /usr/ports && make search name=package Search by name
cd /usr/ports && make search key=search_string Search comments, descriptions and dependencies
View information about a software package

Before installing a software package, we can get a lot of useful information by carefully reading the package description. In addition to human-readable text, these typically include metadata like version numbers and a list of the package's dependencies.

system Order illustrate
Debian / Ubuntu apt-cache show package Display local cache information about packages
apt show package
dpkg -s package Display the current installation status of the package
CentOS yum info package
yum deplist package List package dependencies
Fedora dnf info package
dnf repoquery --requires package List package dependencies
FreeBSD Packages pkg info package Display information about installed packages
FreeBSD Ports cd /usr/ports/category/port && cat pkg-descr
Install package from repository

After knowing the package name, you can usually install it and its dependencies with one command. You can also install multiple packages at once, just list them all.

system Order illustrate
Debian / Ubuntu sudo apt-get install package
sudo apt-get install package1 package2 ... Install all listed packages
sudo apt-get install -y package Where apt prompts whether to continue, the default is yes
sudo apt install package Display a colored progress bar
CentOS sudo yum install package
sudo yum install package1 package2 ... Install all listed packages
sudo yum install -y package When yum prompts whether to continue, it will directly default to yes
Fedora sudo dnf install package
sudo dnf install package1 package2 ... Install all listed packages
sudo dnf install -y package Where dnf prompts whether to continue, the default is yes
FreeBSD Packages sudo pkg install package
sudo pkg install package1 package2 ... Install all listed packages
FreeBSD Ports cd /usr/ports/category/port && sudo make install Build and install a port from source
Install a package from the local file system

For a given operating system, sometimes some software does not officially provide the corresponding package, then the developer or supplier will need to provide the download of the package file. You can usually retrieve these packages through a web browser, or retrieve this information through the command line curl. After downloading the package to the target system, we can usually install it with a single command.

On Debian-derived systems, dpkg is used to process individual package files. If a package has unmet dependencies, then we can use gdebi to retrieve them from the official repository.

On CentOS and Fedora systems, yum and dnf are used to install individual files and handle required dependencies.

system Order illustrate
Debian / Ubuntu sudo dpkg -i package.deb
sudo apt-get install -y gdebi && sudo gdebi package.deb Install gdebi, then use gdebi to install package.deb and handle missing dependencies
CentOS sudo yum install package.rpm
Fedora sudo dnf install package.rpm
FreeBSD Packages sudo pkg add package.txz
sudo pkg add -f package.txz Even installed packages will be reinstalled
Remove one or more installed packages

Because the package manager knows what files are provided by a given package, it can often cleanly remove those files from the system if a piece of software is no longer needed.

system Order illustrate
Debian / Ubuntu sudo apt-get remove package
sudo apt remove package
sudo apt-get autoremove Delete unnecessary packages
CentOS sudo yum remove package
Fedora sudo dnf erase package
FreeBSD Packages sudo pkg delete package
sudo pkg autoremove Delete unnecessary packages
FreeBSD Ports sudo pkg delete package
cd /usr/ports/path_to_port && make deinstall Uninstall port
apt command

Admins of Debian family distributions are usually familiar with apt-get and apt-cache. Less well known is the simplified apt interface, which is designed for interactive use.

Traditional commands Equivalent apt command
apt-get update apt update
apt-get dist-upgrade apt full-upgrade
apt-cache search string apt search string
apt-get install package apt install package
apt-get remove package apt remove package
apt-get purge package apt purge package

Although apt is usually a shortcut for a specific operation, it cannot completely replace traditional tools, and its interface may change with different versions to improve usability. If you use package management commands in scripts or shell pipelines, it's best to stick with apt-get and apt-cache.

Get help

In addition to web-based documentation, remember that we can get most commands from the Unix manual page (often called the man page) through the shell. For example, to read a certain page, you can use man:

In man, you can use the arrow keys to navigate. Press / to search the text within the page and use q to exit.

system Order illustrate
Debian / Ubuntu man apt-get Updating the local package database and working with packages
man apt-cache Search in the local package database
man dpkg Works with individual package files and can query installed packages
man apt Conduct the most basic operations through a simpler, user-friendly interface
CentOS man yum
Fedora man dnf
FreeBSD Packages man pkg Works with precompiled binary packages
FreeBSD Ports man ports Working with the Ports collection

The above is the detailed content of Analyze the functions and characteristics of apt, yum, dnf and pkg. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete