Example: 1 list all available packages
[Email protected]:~$ apt-cache pkgnames
Account-plugin-yahoojp
Ceph-fuse
Dvd+rw-tools
E3
Gnome-commander-data
Grub-gfxpayload-lists
Gweled
.......................................
Example: 2 search for packages with keywords
This command is useful when you are unsure of the name of the package, as long as the Apt-cache (LCTT: The original is apt-get, should be a clerical error) after entering the key words related to the package.
[Email protected]:~$ 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.
[Email protected]:~$ 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 show basic information for a specific package
[Email protected]:~$ apt-cache show Postfix
Package:postfix
Priority:optional
Section:mail
installed-size:3524
Maintainer:lamontjones<[email protected]>
Architecture:amd64
Version:2.11.1-1
Replaces:mail-transport-agent
Provides:default-mta, Mail-transport-agent
.....................................................
Example: 4 listing dependencies for a package
[Email protected]:~$ apt-cache depends postfix
Postfix
Depends:libc6
depends:libdb5.3
Depends:libsasl2-2
depends:libsqlite3-0
depends:libssl1.0.0
| Depends:debconf
Depends:<debconf-2.0>
Cdebconf
Debconf
Depends:netbase
Depends:adduser
Depends:dpkg
............................................
Example: 5 displaying cache statistics using Apt-cache
[Email protected]:~$ apt-cache Stats
Totalpackage names:60877 (1,218 k)
Totalpackage structures:102824 (5,758 k)
Normal packages:71285
Purevirtual packages:1102
Singlevirtual packages:9151
Mixedvirtual packages:1827
missing:19459
Total distinct versions:74913 (5,394 k)
Total distinct descriptions:93792 (2,251 k)
Total dependencies:573443 (16.1 M)
Total Ver/file relations:78007 (1,872 k)
Totaldesc/file relations:93792 (2,251 k)
Totalprovides mappings:16583 (332 k)
Total globbed strings:171 (2,263)
Total dependency version space:2,665 K
Total Slack space:37.3 K
Total space accounted for:29.5 M
Example: 6 update warehouse with "Apt-get Update"
Using the command "Apt-get Update", we can re-synchronize the file index from the source repository. The index of the package is retrieved from "/etc/apt/sources.list".
[Email protected]:~$ 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 using the Apt-get installation package
[Email protected]:~$ sudo apt-get install Icinga
The above command installs a package called "Icinga".
Example: 8 Upgrading all installed Packages
[Email protected]:~$ 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:
[Email protected]:~$ sudo apt-get install FileZilla--only-upgrade
Example: 10 uninstalling a package using Apt-get
[Email protected]:~$ sudo apt-get remove Skype
The above command will only remove the Skype package, and if you want to delete its profile, use the "purge" option in the Apt-get command. As shown below:
[Email protected]:~$ sudo apt-get purge skype
We can use the above two commands together:
[Email protected]:~$ sudo apt-get remove--purge skype
Example: 11 downloading a package in the current directory
[Email protected]:~$ sudo apt-get download Icinga
Get:1 http://in.archive.ubuntu.com/ubuntu/utopic/universe icinga amd64 1.11.6-1build1 [1,474 B]
fetched1,474 In1s (1,363 b/s)
The above directory will download the Icinga package to your current working directory.
Example: 12 cleanup of disk space consumed by a local package
[Email protected]:~$ sudo apt-get clean
The above command empties the disk space consumed by the Apt-get downloaded package.
We can also use the "autoclean" option instead of "clean", the main difference between the two is that AutoClean cleanup is no longer used and useless downloads.
[Email protected]:~$ sudo apt-get autoclean
Readingpackage lists ... Done
Building Dependency Tree
Reading state information ... Done
Example: 13 Deleting a package using "Autoremove"
When you use "Autoremove" in the Apt-get command, it removes packages that are installed to satisfy dependencies and are now useless.
[Email protected]:~$ sudo apt-get autoremove icinga
Example: 14 shows the update log for a package
[Email protected]:~$ sudo apt-get changelog apache2
Get:1changelogfor Apache2 (http://changelogs.ubuntu.com/changelogs/pool/main/a/apache2/apache2_2.4.10-1ubuntu1/ Changelog) [195 KB]
Fetched195 KB in3s (60.9 kb/s)
The above command downloads the apache2 update log and displays it on your screen.
Example: 15 using the CHECK option to display a corrupted dependency
[Email protected]:~$ sudo apt-get check
Readingpackage lists ... Done
Building Dependency Tree
Reading state information ... Done
Apt-get and Apt-cache command examples show