what is linux apt

青灯夜游
Release: 2023-04-10 17:11:05
Original
4081 people have browsed it

APT is a software package management tool under Linux systems that can automatically download, configure, and install software packages in binary or source code format; most apt commands must be run as a user with sudo permissions. APT was first designed as the front end of dpkg, used to process deb format software packages; now after modification by the APT-RPM organization, APT can be installed on systems that support RPM to manage RPM packages.

what is linux apt

The operating environment of this tutorial: Ubuntu 21.04 system, Dell G3 computer.

If we want to install a certain software through the Linux command line, just enter the following command directly at the command line:

sudo apt-get update sudo apt-get install
Copy after login

This installation method is through theapt toolTo achieve installation, what exactly is apt?

1. APT Tool

The full name of APTAdvancedPackagingTool , that is,Advanced Packaging Tool, is asoftware package management toolunder the Linux system. APT simplifies the process of managing software on Unix systems by automatically downloading, configuring, and installing software packages in binary or source code format. Apt can be used to:

  • Install the application

  • Remove the application

  • Keep the application as The latest

  • There are more functions...

APT was first designed as the front end of dpkg (Debian Package), used to process deb format software package. Now after modification by the APT-RPM organization, APT can be installed to manage RPM packages on systems that support RPM. This package manager contains multiple tools starting with apt-, such asapt-getapt-cacheapt-cdrometc.

In simple terms, APT is acommand line utility, for# installation, update, management, delete, finding .... Most apt commands must be run as a user withsudo permissions.

  • apt is suitable for Ubuntu, Debian and related Unix distributions, not suitable for redhat, centos...

2. How APT works

APT is aclient/server system. First copy all deb packages on the server (deb - file extension of Debian software package format); then use APT's analysis tool - genbasedir to analyze all deb packages based on the header information of each deb package, and analyze The results are recorded in a file -DEB Index List. The DEB index list of APT servers is placed in the base folder. Once the deb package in the APT server is changed, be sure to use genbasedir to generate a new DEB index list. When installing or upgrading, the client must first query the DEB index list to obtain all software packages with dependencies, and download them to the client together for installation.

When the client needs to install, upgrade or delete a software package, the client computer obtains the compressed file of the DEB index list, decompresses it and places it in the /var/state/apt/lists/ directory. When the client uses the apt-get install or apt-get upgrade command, the data in this folder will be compared with the DEB database in the client computer to know which DEBs are installed, not installed, or can be upgraded. of.

The client needs toregularlydownload apackage listfrom the server, because the apt tool is actuallyavailable packages Work on the database. When performing an installation operation, the apt-get tool will search for relevant information about the target software in theavailable software package databaseof the local

Download the software on the server and install it. Therefore, before installation, you usually update the local software package database through ### sudo apt-get update ###. #########3. APT commands############ (1) apt-get common commands###### ##sudo apt-get Install ##sudo apt-get --reinstall install software package, such as: the system is damaged , some incorrect configurations cause the software to not work properly... sudo apt-get upgrade All installed packages ##sudo apt-get full-upgrade remove autoremove purge ) ## by default. Generate package sudo apt-get
Command Description
##sudo apt-getupdate UpdateLocal packageDatabase
install software package
Reinstall the
Upgrade
Full UpgradeInstalled software package ##sudo apt-get
RemoveInstalled software packages (including software packages that have dependencies on the removed software package, but do not include the configuration file of the software package) sudo apt-get
RemoveBefore dependent on other software packages, but now no longer used Software package sudo apt-get
Completely remove thepackage (including the package'sconfiguration file##sudo apt-getclean
RemoveThe installed software package downloaded to the local area is saved in /var/cache/apt/archives/#sudo apt-getlist
list sudo apt-getsearch
##Searchsoftware packageshow
Displaypackage specific information, such as : Version number, installation size, dependencies, etc. (2) apt-get common parameters

ParameterDescription

##-y Automatic response The option to install the software package is very useful in some automated installation scripts -s Simulation Installation -q quiet installation method, specify multiple -q= ##Fix Broken dependencies Download only , Do not install Already installed but there may be problems Software package
qor# (# represents a number, used for setting Silent level), very useful when you don’t want too much screen output during the installation process-f
-d
--reinstall ##Reinstall
--install-suggests Also install thesuggested installation## given by APT #’s software package

四、使用 apt 命令管理基于 Debian 和 Ubuntu 的 Linux 发行版中的包

我在本教程中使用 Ubuntu 21.04,但你可以使用任何其他基于 Debian/Ubuntu 的 Linux 发行版,例如 Linux Mint、elementary OS、Linux Lite 等。

4.1、使用 apt 更新包数据库

apt 作用于可用包的数据库。如果数据库没有更新,系统将不知道是否有可更新的软件包可用。这就是为什么在任何 Linux 系统中进行了全新安装后,首先要更新存储库。

更新包数据库需要超级用户权限,因此您需要使用sudo

sudo apt update
Copy after login

运行此命令看到从各种服务器检索的包信息:

what is linux apt
在此处看到三种类型的行:HitGetIgn。基本上这些是:

  • 命中(Hit):包版本与之前的版本没有变化。
  • 忽略(Ign):包被忽略。要么是包版本太新,它甚至懒得检查,要么在检索文件时出错,但错误微不足道,因此被忽略。
  • 获取(Get):有一个新版本可用。它将下载有关版本的信息(而不是包本身)。您可以在上面的屏幕截图中看到带有“获取(Get)”行的下载信息(大小以kb为单位)。

4.2、使用 apt 升级已安装的软件包

更新软件包数据库后,就可以升级已安装的软件包。最方便的方法是升级所有具有可用更新的软件包。可以简单地使用以下命令:

sudo apt upgrade
Copy after login

这将显示将要升级的所有软件包的数量和种类。

what is linux aptwhat is linux apt

还有另一种方法可以使用以下命令提供完整升级:

sudo apt full-upgrade
Copy after login

full-upgradeupgrade的工作原理相同,只是如果系统升级需要删除系统上已安装的软件包,它会这样做。然而,正常的升级命令不会这样做。

4.3、apt update 和 apt upgrade 的区别

虽然听起来像当执行apt update时,它会更新软件包,你将获得最新版本的软件包。但事实并非如此。apt update 只更新包的数据库

例如,如果你安装了 XYZ 包 1.3 版,则在 apt 更新后,数据库将知道有更新的 1.4 版可用。当你在 apt update 之后执行 apt upgrade 时,它会将已安装的软件包升级(或更新)到较新的版本。

这就是为什么使用此命令更新 Ubuntu 系统最快、最方便的原因:

sudo apt update && sudo apt upgrade -y
Copy after login

4.4、使用 apt 安装新软件包

如果已经知道包的名称,则可以使用以下命令进行安装:

sudo apt install 
Copy after login

只需将替换为所需的包。假设你想安装mplayer,你可以简单地使用下面的命令:

sudo apt install mplayer
Copy after login

what is linux aptwhat is linux apt

可以使用自动完成功能。当不确定确切的包名称时,可以输入几个字母并按Tab,它会建议所有以这些字母开头的可用的包。例如:

注意是按Tab,而不是Enter!

使用自动完成功能查找具有给定名称的包:
what is linux apt

4.5、使用 apt 安装多个软件包

不必一次只安装一个软件包。可以通过同时提供多个软件包名称来一次安装多个软件包:

sudo apt install   
Copy after login

4.6、如果在已安装的软件包上运行 apt install 会怎样

这将只查看数据库,如果找到更新的版本,它会将已安装的软件包升级到较新的软件包。因此,使用它不会造成任何伤害,除非你不希望它升级。

what is linux apt

4.7、在不升级的情况下安装软件包

如果由于某种原因你想安装一个包,但不想升级,如果它已经安装了。在这种情况下,你可以通过以下方式使用选项–no-upgrade

sudo apt install  --no-upgrade
Copy after login

what is linux apt

4.8、只升级软件包,而不是安装它

如果你只想升级软件包但不想安装它(如果尚未安装),则可以使用以下命令执行此操作:

sudo apt install  --only-upgrade
Copy after login

what is linux apt

4.9、安装特定版本的应用程序

默认情况下,将为应用程序安装存储库中可用的最新版本。但是如果不想安装最新版本,可以指定版本号。你需要知道要安装的确切版本号。

只需在包名称后添加=version即可。

sudo apt install =
Copy after login

4.10、使用 apt 删除已安装的软件包

删除软件包就像安装它们一样简单。只需使用以下命令:

sudo apt remove 
Copy after login

what is linux apt
卸载软件包的另一种方法是使用清除。该命令的使用方式如下:

sudo apt purge 
Copy after login

apt remove 和 apt purge 的区别

  • apt remove只是删除包的二进制文件。它留下了残留的配置文件。
  • apt purge删除与包相关的所有内容,包括配置文件。

如果你习惯于apt remove删除特定软件然后重新安装它,你的软件将具有相同的配置文件。当然,再次安装时会要求你覆盖现有的配置文件。

当你弄乱了程序的配置,你想从系统中完全清除它的痕迹再重新开始,清除会很有用。也可以在已删除的包上使用apt purge

what is linux apt通常,apt remove卸载软件包绰绰有余。

4.11、搜索packages

这不是搜索包的最好方式。但是当你在寻找一些特定的库时,这很有用。只需将以下命令与所需的搜索词一起使用,就可以找到包含搜索词的所有包。

apt search 
Copy after login

what is linux apt
what is linux apt

4.12、查看package的内容

如果你想在安装或删除软件包之前了解有关软件包的更多信息,可以使用以下命令:

apt show 
Copy after login

这将显示有关给定包的信息,例如其依赖项、安装和下载大小、包的不同来源、包内容的描述等:

what is linux apt

4.13、列出可升级和已安装的版本

apt 命令有一个名为 list 的新选项。使用此命令,可以查看所有准备升级的较新版本的软件包:

apt list --upgradable
Copy after login

what is linux apt
还可以使用--installed选项查看系统上所有已安装的软件包:

apt list --installed
Copy after login

what is linux apt

还有第三个选项,称为–all-versions。它将列出可用于你的系统的所有软件包:

apt list --all-versions
Copy after login

what is linux apt
what is linux apt

4.14、使用 apt 清理系统

与 apt-get 不同,这里没有 clean 和 autoclean 命令。但是仍然可以使用autoremove选项释放一些磁盘空间:

sudo apt autoremove
Copy after login

安装软件时会自动安装一些满足依赖关系的库和包。如果软件包被删除,这些自动安装的库和包虽然没有用,但仍会保留在系统中。可以使用此命令清除掉。

what is linux apt

相关推荐:《Linux视频教程

The above is the detailed content of what is linux apt. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!