Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use apt, yum, dnf and pkg in Linux

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use apt, yum, dnf and pkg in Linux. It is very detailed and has certain reference value. Friends who are interested must finish it!

Package management system: a brief overview

Most package systems are built around a collection of package files. The package file is usually 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, as well as a list of other packages needed to install and run them.

Although the functions and benefits of these package management systems are roughly the same, packaging formats and tools vary from platform to platform:

Operating system format tools Debian.debapt, apt-cache, apt-get, dpkgUbuntu.debapt, apt-cache, apt-get, dpkgCentOS.rpmyumFedora.rpmdnfFreeBSDPorts, .txzmake, pkg

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

Most of the recently released debian derivatives include the apt command, which provides a concise and unified interface for common operations that are usually handled by the 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, you interact with separate package files and repositories through yum.

In the recent version of Fedora, yum has been replaced by dnf, and dnf is a modern branch of it, which retains most of the yum interface.

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

Update package list

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

System command Debian / Ubuntusudo apt-get updatesudo apt updateCentOSyum check-updateFedoradnf check-updateFreeBSD Packagessudo pkg updateFreeBSD Portssudo portsnap fetch update

Update installed packages

In the absence of a package system, it is a daunting task to ensure that all installed software on the machine is kept in a state of *. You will have to track upstream changes and security alerts for hundreds of different packages. Although the package manager does not solve all the problems encountered when upgrading the software, it does enable you to use some commands to maintain most system components.

On FreeBSD, upgrading an installed ports can introduce destructive changes, and some steps require manual configuration, so read / usr/ports/UPDATING before updating through portmaster.

The system command states that Debian / Ubuntusudo apt-get upgrade updates only installed packages sudo apt-get dist-upgrade may add or remove packages to meet new dependencies sudo apt upgrade and apt-get upgrade like sudo apt full-upgrade and apt-get dist-upgrade similar to CentOSsudo yum updateFedorasudo dnf upgradeFreeBSD Packagessudo pkg upgradeFreeBSD Portsless / 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-an install portmaster and then use it to update the installed ports

Search for a package

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

The system command instructs Debian / Ubuntuapt-cache search search_stringapt search search_stringCentOSyum search search_stringyum search all search_string to search all fields, including the description Fedoradnf search search_stringdnf search all search_string search all fields Include description FreeBSD Packagespkg 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 Portscd / 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 the package, we can get a lot of useful information by carefully reading the description of the package. In addition to human-readable text, this usually includes metadata such as version numbers and lists of package dependencies.

The system command states that Debian / Ubuntuapt-cache show package displays local cache information about packages apt show packagedpkg-s package displays the current installation status of packages CentOSyum info packageyum deplist package lists package dependencies Fedoradnf info packagednf repoquery-- requires package lists packages dependencies FreeBSD Packagespkg info package displays information about installed packages FreeBSD Portscd / usr/ports/category/port & & cat pkg-descr

Install the package from the repository

Once you know the package name, you can usually use a command to install it and its dependencies. You can also install multiple packages at once, just list them all.

The system command describes Debian / Ubuntusudo apt-get install packagesudo apt-get install package1 package2... Install all listed packages sudo apt-get install-y package directly defaults to yessudo apt install package to display a colored progress bar CentOSsudo yum install packagesudo yum install package1 package2 where apt prompts you to continue. Install all listed packages sudo yum install-y package directly defaults to yesFedorasudo dnf install packagesudo dnf install package1 package2 where yum prompts you to continue. Install all listed packages sudo dnf install-y package directly defaults to yesFreeBSD Packagessudo pkg install packagesudo pkg install package1 package2 where dnf prompts you to continue. Install all listed packages FreeBSD Portscd / usr/ports/category/port & & sudo make install install a port from the source build

Install a package from the local file system

For a given operating system, sometimes some software officially does not provide the corresponding package, then the developer or vendor will need to provide the download of the package file. You can usually retrieve these packages through a web browser or 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 unsatisfied dependencies, 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 the required dependencies.

The system command instructs Debian / Ubuntusudo dpkg-I package.debsudo apt-get install-y gdebi & & sudo gdebi package.deb to install gdebi, then use gdebi to install package.deb and deal with missing dependencies CentOSsudo yum install package.rpmFedorasudo dnf install package.rpmFreeBSD Packagessudo pkg add package.txzsudo pkg add-f package.txz will reinstall even packages that are already installed

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 usually cleanly remove these files from the system.

The system command instructs Debian / Ubuntusudo apt-get remove packagesudo apt remove packagesudo apt-get autoremove to delete unwanted packages CentOSsudo yum remove packageFedorasudo dnf erase packageFreeBSD Packagessudo pkg delete packagesudo pkg autoremove delete unwanted packages FreeBSD Portssudo pkg delete packagecd / usr/ports/path_to_port & & make deinstall uninstall port

Apt command

Administrators 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 command equivalent apt command apt-get updateapt updateapt-get dist-upgradeapt full-upgradeapt-cache search stringapt search stringapt-get install packageapt install packageapt-get remove packageapt remove packageapt-get purge packageapt purge package

Although apt is usually a shortcut to a specific operation, it is not a complete substitute for traditional tools, and its interface may change from version to version to improve usability. If you use package management commands in scripts or shell pipes, then * insist on using apt-get and apt-cache.

Get help

In addition to web-based documentation, keep in mind that we can get most of the commands from the Unix man pages (often referred to as man pages) through shell. For example, to read a page, you can use man:

Man page

In man, you can use the arrow keys to navigate. Press / search for the text on the page and use Q to exit.

System commands instruct Debian / Ubuntuman apt-get to update the local package database and work with packages man apt-cache searches the local package database for man dpkg and separate package files to work together and to query installed packages man apt by making it more concise User-friendly interface for the most basic operations CentOSman yumFedoraman dnfFreeBSD Packagesman pkg and precompiled binaries work together FreeBSD Portsman ports and Ports collections work together these are all the contents of the article "how to use apt, yum, dnf and pkg in Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report