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-get and apt-cache commands in Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article focuses on "how to use apt-get and apt-cache commands in Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to use the apt-get and apt-cache commands in Linux.

Apt-get and apt-cache are package management tools under the command line in Ubuntu Linux. The GUI version of apt-get is the Synaptic package manager. In this article, we will show 15 different examples of apt-get and apt-cache commands.

Example: 1 list all available packages

The code is as follows:

Linuxtechi@localhost:~$ apt-cache pkgnames

Account-plugin-yahoojp

Ceph-fuse

Dvd+rw-tools

E3

Gnome-commander-data

Grub-gfxpayload-lists

Gweled

..

Example: 2 search packages with keywords

This command is useful when you are unsure of the package name, as long as you type the keywords associated with the package after the apt-cache.

The code is as follows:

Linuxtechi@localhost:~$ apt-cache search "web server"

Apache2-Apache HTTP Server

Apache2-bin-Apache HTTP Server (binary files and modules)

Apache2-data-Apache HTTP Server (common files)

Apache2-dbg-Apache debugging symbols

Apache2-dev-Apache HTTP Server (development headers)

Apache2-doc-Apache HTTP Server (on-site documentation)

Apache2-utils-Apache HTTP Server (utility programs for web servers)

....

Note: if you install the "apt-file" package, we can use the configuration file to search for the package as follows.

The code is as follows:

Linuxtechi@localhost:~$ apt-file search nagios.cfg

Ganglia-nagios-bridge: / usr/share/doc/ganglia-nagios-bridge/nagios.cfg

Nagios3-common: / etc/nagios3/nagios.cfg

Nagios3-common: / usr/share/doc/nagios3-common/examples/nagios.cfg.gz

Pnp4nagios-bin: / etc/pnp4nagios/nagios.cfg

Pnp4nagios-bin: / usr/share/doc/pnp4nagios/examples/nagios.cfg

Example: 3 display basic information for a specific package

The code is as follows:

Linuxtechi@localhost:~$ apt-cache show postfix

Package: postfix

Priority: optional

Section: mail

Installed-Size: 3524

Maintainer: LaMont Jones

Architecture: amd64

Version: 2.11.1-1

Replaces: mail-transport-agent

Provides: default-mta, mail-transport-agent

...

Example: 4 list package dependencies

The code is as follows:

Linuxtechi@localhost:~$ apt-cache depends postfix

Postfix

Depends: libc6

Depends: libdb5.3

Depends: libsasl2-2

Depends: libsqlite3-0

Depends: libssl1.0.0

| | Depends: debconf |

Depends:

Cdebconf

Debconf

Depends: netbase

Depends: adduser

Depends: dpkg

....

Example: 5 display cache statistics using apt-cache

The code is as follows:

Linuxtechi@localhost:~$ apt-cache stats

Total package names: 60877 (1218 k)

Total package structures: 102824 (5758 k)

Normal packages: 71285

Pure virtual packages: 1102

Single virtual packages: 9151

Mixed virtual packages: 1827

Missing: 19459

Total distinct versions: 74913 (5394 k)

Total distinct descriptions: 93792 (2251 k)

Total dependencies: 573443 (16.1 M)

Total ver/file relations: 78007 (1872 k)

Total Desc/File relations: 93792 (2251 k)

Total Provides mappings: 16583 (332k)

Total globbed strings: 171 (2263)

Total dependency version space: 2665 k

Total slack space: 37.3 k

Total space accounted for: 29.5 M

Example: 6 use "apt-get update" to update the warehouse

Using the command "apt-get update", we can resynchronize the file index from the source repository. The index of the package is retrieved from "/ etc/apt/sources.list".

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get update

Ign http://extras.ubuntu.com utopic InRelease

Hit http://extras.ubuntu.com utopic Release.gpg

Hit http://extras.ubuntu.com utopic Release

Hit http://extras.ubuntu.com utopic/main Sources

Hit http://extras.ubuntu.com utopic/main amd64 Packages

Hit http://extras.ubuntu.com utopic/main i386 Packages

Ign http://in.archive.ubuntu.com utopic InRelease

Ign http://in.archive.ubuntu.com utopic-updates InRelease

Ign http://in.archive.ubuntu.com utopic-backports InRelease

....

Example: 7 install packages using apt-get

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get install icinga

The above command installs a package called "icinga".

Example: 8 upgrade all installed packages

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get upgrade

Example: 9 Update a specific package

The "install" option in the apt-get command is followed by "- only-upgrade" to update a specific package, as follows:

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get install filezilla-only-upgrade

Example: 10 uninstall packages using apt-get

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get remove skype

The above command only deletes the skype package. If you want to delete its configuration file, use the "purge" option in the apt-get command. As follows:

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get purge skype

We can use the above two commands together:

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get remove-purge skype

Example: 11 download the package in the current directory

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get download icinga

Get:1 http://in.archive.ubuntu.com/ubuntu/ utopic/universe icinga amd64 1.11.6-1build1 [1474 B]

Fetched 1474 B in 1s (1363 Bhand s)

The above directory will download the icinga package to your current working directory.

Example: 12 Clean up disk space occupied by local packages

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get clean

The above command empties the disk space occupied by packages downloaded by apt-get.

We can also use the "autoclean" option instead of "clean". The main difference between the two is that autoclean cleans up downloads that are no longer used and useless.

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get autoclean

Reading package lists... Done

Building dependency tree

Reading state information... Done

Example: 13 delete a package using "autoremove"

When you use "autoremove" in the apt-get command, it removes packages that are installed to satisfy dependencies and are not currently in use.

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get autoremove icinga

Example: 14 displays the update log of the package

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get changelog apache2

Get:1 Changelog for apache2 (http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.4.10-1ubuntu1/changelog) [195 kB]

Fetched 195 kB in 3s (60.9 kB/s)

The above command downloads apache2's update log and displays it in pages on your screen.

Example: 15 use the "check" option to display corrupted dependencies

The code is as follows:

Linuxtechi@localhost:~$ sudo apt-get check

Reading package lists... Done

Building dependency tree

Reading state information... Done

At this point, I believe you have a deeper understanding of "the use of apt-get and apt-cache commands in Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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