By Linux Guru 01.01.0001
Useful Basic Commands of APT-GET and APT-CACHE for Package Management
Excerpt
This article explains how quickly you can learn to install, remove, update and search software packages using apt-get and apt-cache commands from the command line.
This article explains how quickly you can learn to install, remove, update and search software packages using apt-get and apt-cache commands from the command line. This article provides some useful commands that will help you to handle package management in Kali-Linux or Debian/Ubuntu based systems.
APT-GET and APT-CACHE Commands
What is apt-get?
The apt-get utility is a powerful and free package management command line program, that is used to work with Ubuntu’s APT (Advanced Packaging Tool) library to perform installation of new software packages, removing existing software packages, upgrading of existing software packages and even used to upgrading the entire operating system.
What is apt-cache?
The apt-cache command line tool is used for searching apt software package cache. In simple words, this tool is used to search software packages, collects information of packages and also used to search for what available packages are ready for installation on Debian or Ubuntu based systems.
1. HowTo List All Available Packages?
To list all the available packages, type the following command.
apt-cache pkgnames
esseract-ocr-epo
pipenightdreams
mumudvb
tbb-examples
libsvm-java
libmrpt-hmtslam0.9
libboost-timer1.50-dev
kcm-touchpad
...
2. HowTo Find Out Package Name and Description of Software?
To find out the package name and with it description before installing, use the ‘search‘ flag. Using “search” with apt-cache will display a list of matched packages with short description. Let’s say you would like to find out description of package ‘vsftpd‘, then command would be.
apt-cache search log4j
liblog4cxx11 - Logging library for C++
liblog4j-extras1.2-java - Extras for Apache log4j
liblog4j-extras1.2-java-doc - Documentation for Extras for Apache log4j.
liblog4j1.2-java - Logging library for java
liblog4j1.2-java-doc - Documentation for liblog4j1.2-java
liblog4j2-java - Apache Log4j - Logging Framework for Java
liblog4net-cil-dev - highly configurable logging API for the CLI
liblog4net1.2-cil - highly configurable logging API for the CLI
...
To find and list down all the packages starting with ‘vsftpd‘, you could use the following command.
apt-cache pkgnames vsftpd
vsftpd
vsftpd-dbg
3. HowTo Check Package Information?
For example, if you would like to check information of package along with it short description say (version number, check sums, size, installed size, category etc). Use ‘show‘ sub command as shown below.
apt-cache show lsof
Package: lsof
Version: 4.93.2+dfsg-1.1
Installed-Size: 451
Maintainer: Andres Salomon <[email protected]>
Architecture: amd64
Depends: libc6 (>= 2.11), libselinux1 (>= 3.1~)
Suggests: perl
Size: 319016
SHA256: a03b5971519f2b2c51e7b4234d6e416ff22ac898e5f3fcc52cd63e4ad6161a77
SHA1: e3b92ac6d0ff4bddbc65c62a271031b78ab63aba
MD5sum: 4c811ccf0a34bcbc6ee6dbb6a90cbfc1
Description: utility to list open files
Lsof is a Unix-specific diagnostic tool. Its name stands
for LiSt Open Files, and it does just that. It lists
information about any files that are open, by processes
currently running on the system.
Description-md5: df6eff5e3fcd44e35327c894b54c92a3
Homepage: https://github.com/lsof-org/lsof
Tag: devel::lang:perl, devel::library, implemented-in::c,
implemented-in::perl, interface::commandline, role::devel-lib,
role::program, scope::utility, use::monitor, use::searching,
works-with::file, works-with::software:running
Section: utils
Priority: standard
Filename: pool/main/l/lsof/lsof_4.93.2+dfsg-1.1_amd64.deb
4. HowTo Check Dependencies for Specific Packages?
Use the ‘showpkg‘ sub command to check the dependencies for particular software packages. whether those dependencies packages are installed or not. For example, use the ‘showpkg‘ command along with package-name.
apt-cache showpkg ccze
Package: ccze
Versions:
0.2.1-6 (/var/lib/apt/lists/http.kali.org_kali_dists_kali-rolling_main_binary-amd64_Packages)
Description Language:
File: /var/lib/apt/lists/http.kali.org_kali_dists_kali-rolling_main_binary-amd64_Packages
MD5: 55cd93dbcf614712a4d89cb3489414f6
Reverse Depends:
airgeddon,ccze
xrootconsole,ccze
hollywood,ccze
colorized-logs,ccze
byobu,ccze
Dependencies:
0.2.1-6 - libc6 (2 2.8) libncurses6 (2 6) libpcre3 (0 (null)) libtinfo6 (2 6) colorize (1 0.3.1-2)
Provides:
0.2.1-6 -
Reverse Provides:
5. HowTo Check statistics of Cache
The ‘stats‘ sub command will display overall statistics about the cache. For example, the following command will display Total package names is the number of packages have found in the cache.
apt-cache stats
Total package names: 103842 (2,908 k)
Total package structures: 92419 (4,066 k)
Normal packages: 60941
Pure virtual packages: 732
Single virtual packages: 21175
Mixed virtual packages: 357
Missing: 9214
Total distinct versions: 61298 (5,394 k)
Total distinct descriptions: 61298 (1,471 k)
Total dependencies: 360099/104067 (8,867 k)
Total ver/file relations: 62133 (1,491 k)
Total Desc/File relations: 61298 (1,471 k)
Total Provides mappings: 25033 (601 k)
Total globbed strings: 196431 (4,446 k)
Total slack space: 88.2 k
Total space accounted for: 32.4 M
Total buckets in PkgHashTable: 196613
Unused: 123044
Used: 73569
Utilization: 37.4182%
Average entries: 1.25622
Longest: 16
Shortest: 1
Total buckets in GrpHashTable: 196613
Unused: 115970
Used: 80643
Utilization: 41.0161%
Average entries: 1.28768
Longest: 6
Shortest: 1
6. How to Update System Packages
The ‘update‘ command is used to resynchronize the package index files from the their sources specified in /etc/apt/sources.list file, or in files /etc/apt/sources.list.d/ The update command fetched the packages from their locations and update the packages to newer version.
apt-get update
Hit:1 http://ftp.halifax.rwth-aachen.de/kali kali-rolling InRelease
Reading package lists... Done
...
7. How to Upgrade Software Packages
The ‘upgrade‘ command is used to upgrade all the currently installed software packages on the system. Under any circumstances currently installed packages are not removed or packages which are not already installed neither retrieved and installed to satisfy upgrade dependencies.
apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
linux-headers-generic linux-image-generic wine1.5
The following packages will be upgraded:
activity-log-manager-common activity-log-manager-control-center
...
However, if you want to upgrade, unconcerned of whether software packages will be added or removed to fulfill dependencies, use the ‘dist-upgrade‘ sub command.
apt-get dist-upgrade
8. HowTo Install or Upgrade Specific Packages?
The ‘install‘ sub command is tracked by one or more packages wish for installation or upgrading.
apt-get install multitail
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
multitail
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 130 kB of archives.
After this operation, 357 kB of additional disk space will be used.
Get:1 http://ftp.halifax.rwth-aachen.de/kali kali-rolling/main amd64 multitail amd64 6.5.0-5 [130 kB]
Fetched 130 kB in 1s (160 kB/s)
Selecting previously unselected package multitail.
(Reading database ... 67147 files and directories currently installed.)
Preparing to unpack .../multitail_6.5.0-5_amd64.deb ...
Unpacking multitail (6.5.0-5) ...
Setting up multitail (6.5.0-5) ...
Processing triggers for man-db (2.9.4-2) ...
9. How to Install Multiple Packages?
You can add more than one package name along with the command in order to install multiple packages at the same time. For example, the following command will install packages nethogs and goaccess
apt-get install nethogs goaccess
Reading package lists... Done
Building dependency tree
Reading state information... Done
goaccess is already the newest version.
nethogs is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 350 not upgraded.
10. How to Install Several Packages using Wildcard
With the help of regular expression you can add several packages with one string. For example, we use * wildcard to install several packages that contains the ‘*name*‘ string, name would be ‘package-name’.
apt-get install '*name*'
11. How to install Packages without Upgrading
Using sub ‘–no-upgrade‘ command will prevent already installed packages from upgrading.
apt-get install packageName --no-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Skipping vsftpd, it is already installed and upgrade is not set.
0 upgraded, 0 newly installed, 0 to remove and 350 not upgraded.
12. How to Upgrade Only Specific Packages
The ‘–only-upgrade‘ command do not install new packages but it only upgrade the already installed packages and disables new installation of packages.
apt-get install packageName --only-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
vsftpd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 350 not upgraded.
13. HowTo Install Specific Package Version?
Let’s say you wish to install only specific version of packages, simply use the ‘=‘ with the package-name and append desired version.
apt-get install vsftpd=2.3.5-5kali
Reading package lists... Done
Building dependency tree
Reading state information... Done
vsftpd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 350 not upgraded.
14. HowTo Remove Packages Without Configuration
To un-install software packages without removing their configuration files (for later re-use the same configuration). Use the ‘remove‘ command as shown.
apt-get remove vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
vsftpd
0 upgraded, 0 newly installed, 1 to remove and 328 not upgraded.
After this operation, 364 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 216156 files and directories currently installed.)
Removing vsftpd ...
vsftpd stop/waiting
Processing triggers for ureadahead ...
Processing triggers for man-db ...
15. HowTo Completely Remove Packages
To remove software packages including their configuration files, use the ‘purge‘ sub command as shown below.
apt-get purge vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
vsftpd*
0 upgraded, 0 newly installed, 1 to remove and 328 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? y
(Reading database ... 216109 files and directories currently installed.)
Removing vsftpd ...
Purging configuration files for vsftpd ...
Processing triggers for ureadahead ...
Alternatively, you can combine both the commands together as shown below.
apt-get remove --purge vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
vsftpd*
0 upgraded, 0 newly installed, 1 to remove and 328 not upgraded.
After this operation, 364 kB disk space will be freed.
Do you want to continue [Y/n]? y
(Reading database ... 216156 files and directories currently installed.)
Removing vsftpd ...
vsftpd stop/waiting
Purging configuration files for vsftpd ...
Processing triggers for ureadahead ...
Processing triggers for man-db ...
16. How I Can Clean Up Disk Space
The ‘clean‘ command is used to free up the disk space by cleaning retrieved (downloaded) .deb files (packages) from the local repository.
apt-get clean
17. HowTo Download Only Source Code of Package
To download only source code of particular package, use the option ‘–download-only source‘ with ‘package-name’ as shown.
apt-get --download-only source vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
Need to get 220 kB of source archives.
Get:1 http://in.archive.ubuntu.com/ubuntu/ quantal/main vsftpd 2.3.5-3ubuntu1 (dsc) [1,883 B]
Get:2 http://in.archive.ubuntu.com/ubuntu/ quantal/main vsftpd 2.3.5-3ubuntu1 (tar) [188 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ quantal/main vsftpd 2.3.5-3ubuntu1 (diff) [30.5 kB]
Fetched 220 kB in 4s (49.1 kB/s)
Download complete and in download only mode
18. HowTo Download and Unpack a Package
To download and unpack source code of a package to a specific directory, type the following command.
apt-get source vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
Need to get 220 kB of source archives.
Get:1 http://in.archive.ubuntu.com/ubuntu/ quantal/main vsftpd 2.3.5-3ubuntu1 (dsc) [1,883 B]
Get:2 http://in.archive.ubuntu.com/ubuntu/ quantal/main vsftpd 2.3.5-3ubuntu1 (tar) [188 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ quantal/main vsftpd 2.3.5-3ubuntu1 (diff) [30.5 kB]
Fetched 220 kB in 1s (112 kB/s)
gpgv: Signature made Thursday 24 May 2012 02:35:09 AM IST using RSA key ID 2C48EE4E
gpgv: Can't check signature: public key not found
dpkg-source: warning: failed to verify signature on .vsftpd_2.3.5-3ubuntu1.dsc
dpkg-source: info: extracting vsftpd in vsftpd-2.3.5
dpkg-source: info: unpacking vsftpd_2.3.5.orig.tar.gz
dpkg-source: info: unpacking vsftpd_2.3.5-3ubuntu1.debian.tar.gz
dpkg-source: info: applying 01-builddefs.patch
dpkg-source: info: applying 02-config.patch
dpkg-source: info: applying 03-db-doc.patch
dpkg-source: info: applying 04-link-local.patch
dpkg-source: info: applying 05-whitespaces.patch
dpkg-source: info: applying 06-greedy.patch
dpkg-source: info: applying 07-utf8.patch
dpkg-source: info: applying 08-manpage.patch
dpkg-source: info: applying 09-s390.patch
dpkg-source: info: applying 10-remote-dos.patch
dpkg-source: info: applying 11-alpha.patch
dpkg-source: info: applying 09-disable-anonymous.patch
dpkg-source: info: applying 12-ubuntu-use-snakeoil-ssl.patch
19. HowTo Download, Unpack and Compile a Package
You can also download, unpack and compile the source code at the same time, using option ‘–compile‘ as shown below.
apt-get --compile source goaccess
Reading package lists... Done
Building dependency tree
Reading state information... Done
Need to get 130 kB of source archives.
Get:1 http://in.archive.ubuntu.com/ubuntu/ quantal/universe goaccess 1:0.5-1 (dsc) [1,120 B]
Get:2 http://in.archive.ubuntu.com/ubuntu/ quantal/universe goaccess 1:0.5-1 (tar) [127 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ quantal/universe goaccess 1:0.5-1 (diff) [2,075 B]
Fetched 130 kB in 1s (68.0 kB/s)
gpgv: Signature made Tuesday 26 June 2012 09:38:24 AM IST using DSA key ID A9FD4821
gpgv: Can't check signature: public key not found
dpkg-source: warning: failed to verify signature on ./goaccess_0.5-1.dsc
dpkg-source: info: extracting goaccess in goaccess-0.5
dpkg-source: info: unpacking goaccess_0.5.orig.tar.gz
dpkg-source: info: unpacking goaccess_0.5-1.debian.tar.gz
dpkg-buildpackage: source package goaccess
dpkg-buildpackage: source version 1:0.5-1
dpkg-buildpackage: source changed by Chris Taylor <[email protected]>
dpkg-buildpackage: host architecture i386
dpkg-source --before-build goaccess-0.5
dpkg-checkbuilddeps: Unmet build dependencies: debhelper (>= 9) autotools-dev libncurses5-dev libglib2.0-dev libgeoip-dev autoconf
dpkg-buildpackage: warning: build dependencies/conflicts unsatisfied; aborting
dpkg-buildpackage: warning: (Use -d flag to override.)
...
20. HowTo Download a Package Without Installing
Using ‘download‘ option, you can download any given package without installing it. For example, the following command will only download ‘nethogs‘ package to current working directory.
apt-get download nethogs
Get:1 Downloading nethogs 0.8.0-1 [27.1 kB]
Fetched 27.1 kB in 3s (7,506 B/s)
21. HowTo Check Change Log of Package?
The ‘changelog‘ flag downloads a package change-log and shows the package version that is installed.
apt-get changelog vsftpd
vsftpd (2.3.5-3ubuntu1) quantal; urgency=low
* Merge from Debian testing (LP: #1003644). Remaining changes:
+ debian/vsftpd.upstart: migrate vsftpd to upstart.
+ Add apport hook (LP: #513978):
- debian/vsftpd.apport: Added.
- debian/control: Build-depends on dh-apport.
- debian/rules: Add --with apport.
+ Add debian/watch file.
+ debian/patches/09-disable-anonymous.patch: Disable anonymous login
by default. (LP: #528860)
* debian/patches/12-ubuntu-us-snakeoil-ssl.patch: Use snakeoil SSL
certificates and key.
-- Andres Rodriguez <[email protected]> Wed, 23 May 2012 16:59:36 -0400
...
22. HowTo Check Broken Dependencies?
The ‘check‘ command is a diagnostic tool. It used to update package cache and checks for broken dependencies.
apt-get check
Reading package lists... Done
Building dependency tree
Reading state information... Done
23. HowTo Search and Build Dependencies?
This ‘build-dep‘ command searches the local repositories in the system and install the build dependencies for package. If the package does not exists in the local repository it will return an error code.
apt-get build-dep netcat
The following NEW packages will be installed:
debhelper dh-apparmor html2text po-debconf quilt
0 upgraded, 5 newly installed, 0 to remove and 328 not upgraded.
Need to get 1,219 kB of archives.
After this operation, 2,592 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://in.archive.ubuntu.com/ubuntu/ quantal/main html2text i386 1.3.2a-15build1 [91.4 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu/ quantal/main po-debconf all 1.0.16+nmu2ubuntu1 [210 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ quantal/main dh-apparmor all 2.8.0-0ubuntu5 [9,846 B]
Get:4 http://in.archive.ubuntu.com/ubuntu/ quantal/main debhelper all 9.20120608ubuntu1 [623 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu/ quantal/main quilt all 0.60-2 [285 kB]
Fetched 1,219 kB in 4s (285 kB/s)
...
24. HowTo Auto clean Apt-Get Cache?
The ‘autoclean‘ command deletes all .deb files from /var/cache/apt/archives to free-up significant volume of disk space.
apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done
25. HowTo Auto remove Installed Packages?
The ‘autoremove‘ sub command is used to auto remove packages that were certainly installed to satisfy dependencies for other packages and but they were now no longer required. For example, the following command will remove an installed package with its dependencies.
apt-get autoremove vsftpd
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'vsftpd' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 350 not upgraded.
I’ve covered most of the available options with apt-get and apt-cache commands, but still there are more options available, you can check them out using ‘man apt-get‘ or ‘man apt-cache‘ from the terminal. I hope you enjoyed reading this article, If I’ve missed anything and you would like me to add to the list. Please feel free to mention in the comment below.