Guide |
Most modern Unix-like operating systems provide a central mechanism for searching and installing software. Software is usually stored in a repository and distributed in the form of a package. The work of handling packages is referred to as package management. Packages provide the basic components of the operating system, as well as shared libraries, applications, services, and documents. |
introduce
In addition to installing software, the package management system provides tools to update packages that have already been installed. The package repository helps ensure that the code used in your system is 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 what is under the package outside the official repository. The packages in a stable version of a release may be obsolete, especially for new or fast iterations. However, package management is a vital skill for both system administrators and developers, and packaged software is a huge asset for mainstream Linux distributions.
This guide is designed to provide a quick introduction to the basics of finding, installing, and upgrading packages in a variety of Linux distributions, and helps you cross-compare these content across multiple systems. Package Management System: A brief overview
Most package systems are built around a collection of package files. A package file is usually an archive file that contains the compiled binaries and other resources for the software, as well as the installation scripts. Package files also contain valuable metadata, including their dependencies, and a list of other packages needed to install and run them.
Although the functionality and benefits of these package management systems are roughly the same, the packaging format and tools vary by platform:
Operating System |
format |
Tools |
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 derivative editions, such as Ubuntu, Linux Mint and Raspbian, have a package format of. Deb. APT's Advanced package management tool provides most common operational commands: Search for 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, APT command as the front end of the underlying dpkg, and sometimes call it directly.
Most recent releases of the Debian derivative include the APT command, which provides a concise, unified interface that can be used for common operations typically handled by Apt-get and Apt-cache commands. This command is optional, but it can be used to simplify some tasks.
CentOS, Fedora and other Red Hat family members use RPM files. In CentOS, the Yum is used to interact with separate package files and repositories.
In the recent Fedora version, Yum has been replaced by DNF, a modern branch of DNF, which retains most of the Yum interfaces.
The FreeBSD binary package system is managed by the PKG command. FreeBSD also provides a Ports collection, a local directory structure and tool that allows users to use Makefile to compile and install packages directly from the source code after they have obtained the source code. Update package List
Most systems have a package database that corresponds to the remote repository locally, and it is best to update the database before installing or upgrading the package. In addition, Yum and DNF automatically check for updates before performing some operations. Of course you can update the system at any time.
system |
Command |
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
In the absence of a package system, it is a daunting task to make sure that all installed software on the machine remains in the latest state. You will have to track the upstream changes and security alerts for hundreds of different packages. Although Package Manager does not solve all the problems that are encountered when upgrading software, it does enable you to use commands to maintain most system components.
On FreeBSD, upgrading an installed ports may introduce disruptive changes, and some steps need to be manually configured, so it's best to read the/usr/ports/updating content before you update through Portmaster.
system |
Command |
Description |
Debian/ubuntu |
sudo apt-get upgrade |
Update only installed Packages |
|
sudo apt-get dist-upgrade |
Packages may be added or deleted to meet new dependencies |
|
sudo apt upgrade |
Similar to the Apt-get upgrade |
|
sudo apt full-upgrade |
Similar to the 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 Ports update prompts (use the UP and down cursor keys to scroll, press Q to exit). |
|
Cd/usr/ports/ports-mgmt/portmaster && sudo make install && sudo portmaster-a |
Install Portmaster and use it to update installed ports |
search for a package
Most distributions offer graphical or menu-driven tools for package collections, and we can sort through the software, which is a great way to discover new software. However, the quickest and most efficient way to find a package is to search using command-line tools.
system |
Command |
Description |
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 descriptions |
Fedora |
DNF Search Search_string |
|
|
DNF Search All Search_string |
Search all fields, including descriptions |
FreeBSD Packages |
PKG Search Search_string |
Search by name |
|
Pkg search-f search_string |
Search by name and return to 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 for comments, descriptions, and dependencies |
View information for a package
Before installing the package, we can get a lot of useful information by carefully reading the description of the package. In addition to human-readable text, these typically include metadata such as version numbers and a list of dependencies for packages.
system |
Command |
Description |
Debian/ubuntu |
Apt-cache Show Package |
Display local cache information about a package |
|
Apt Show package |
|
|
Dpkg-s Package |
Displays the current installation status of the package |
Centos |
Yum Info Package |
|
|
Yum Deplist Package |
List the dependencies of the package |
Fedora |
DNF Info Package |
|
|
DNF Repoquery--requires Package |
List the dependencies of the package |
FreeBSD Packages |
PKG Info Package |
Display information for installed packages |
FreeBSD Ports |
Cd/usr/ports/category/port && Cat Pkg-descr |
|
installing packages from the repository
After you know the package name, you can usually install it and its dependencies with a single command. You can also install multiple packages at once, just list them all.
system |
Command |
Description |
Debian/ubuntu |
sudo apt-get install package |
|
|
sudo apt-get install package1 package2 ... |
Install all the listed packages |
|
sudo apt-get install-y Package |
Direct default yes where apt prompts for continuation |
|
sudo apt install package |
Show a Colored progress bar |
Centos |
sudo yum install package |
|
|
sudo yum install package1 package2 ... |
Install all the listed packages |
|
sudo yum install-y package |
Direct default yes where Yum prompts to continue |
Fedora |
sudo DNF install package |
|
|
sudo DNF install Package1 package2 ... |
Install all the listed packages |
|
sudo DNF install-y Package |
Direct default yes where DNF prompts to continue |
FreeBSD Packages |
sudo pkg Install package |
|
|
sudo pkg install package1 package2 ... |
Install all the listed packages |
FreeBSD Ports |
Cd/usr/ports/category/port && sudo make install |
Install a port from the source code build |
install a package from the local file system
For a given operating system, sometimes some software officials do not provide the appropriate packages, then the developer or vendor will need to provide a download of the package files. You can usually retrieve these packages through a Web browser, or use the command line curl to retrieve the information. After downloading the package to the target system, we can usually install it through a single command.
On Debian-derived systems, dpkg is used to process individual package files. If a package has unsatisfied dependencies, then we can retrieve them from the official repository using Gdebi.
On CentOS and Fedora systems, yum and DNF are used to install individual files and to handle the dependencies that are needed.
system |
Command |
Description |
Debian/ubuntu |
sudo dpkg-i package.deb |
|
|
sudo apt-get install-y gdebi && sudo gdebi package.deb |
Install Gdebi and 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 are reinstalled |
to delete one or more installed packages
Because the package manager knows which files are provided by a given package, if a software is no longer needed, it can often cleanly purge the files from the system.
system |
Command |
Description |
Debian/ubuntu |
sudo apt-get Remove Package |
|
|
sudo apt Remove package |
|
|
sudo apt-get autoremove |
Delete unwanted Packages |
Centos |
sudo yum Remove package |
|
Fedora |
sudo DNF Erase Package |
|
FreeBSD Packages |
sudo pkg Delete package |
|
|
sudo pkg autoremove |
Delete unwanted Packages |
FreeBSD Ports |
sudo pkg Delete package |
|
|
Cd/usr/ports/path_to_port && make Deinstall |
Uninstall port |
apt Command
Administrators of the Debian family release are usually familiar with Apt-get and Apt-cache. Less known is the simplified apt interface, which is designed for interactive use.
Traditional Command |
the 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 to a particular action, it does not completely replace the traditional tool, and its interface may change with the version to improve usability. If you use package management commands in scripts or shell pipes, it is best to stick with Apt-get and Apt-cache. Get help
In addition to web-based documents, keep in mind that we can get most of the commands from the Unix man page (usually called the man page) from the shell. For example, to read a page, you can use man:
In man, you can navigate with the arrow keys. Press/Search the text inside the page and use Q to exit.
system |
Command |
Description |
Debian/ubuntu |
Mans Apt-get |
Update the local package database and work with the package |
|
Mans Apt-cache |
Search in the local package database |
|
Mans dpkg |
Works with a separate package file and can query for installed packages |
|
Mans APT |
Basic operations with a more concise, user-friendly interface |
Centos |
Mans Yum |
|
Fedora |
Mans DNF |
|
FreeBSD Packages |
Mans PKG |
Work with a precompiled binary package |
FreeBSD Ports |
Mans ports |
Work with the Ports collection |
Via:https://www.digitalocean.com/community/tutorials/package-management-basics-apt-yum-dnf-pkg
Author: Brennen bearnes Translator: Snapcrafter proofreading: Wxy
This article by LCTT original compilation, Linux China honor launch
Reproduced in this article from: http://www.linuxprobe.com/aptyum-dnfpkg-diff.html free to provide the latest Linux technology tutorials Books, for the open source technology enthusiasts to do more and better: http://www.linuxprobe.com/