, , , , , ,

Because Kali Linux is very popular among those starting out in computer security, and some of us spent months shaping our toolsets, it’s worth covering the main points of the Advanced Package Tool (apt).
The Advanced Package Tool (apt) is one of several package managers that have made life easier since the days when it was more common to configure and compile software from source. Through dselect and dpkg, APT handles the download, compile and dependency resolving stages for us.

Most users would interact with APT through a GUI such as the Synaptic Package Manager, but the command line provides more options and finer control over package management. Plus there might be occasions where the command line must be used for resolving issues. Or perhaps you installed a distro without a desktop environment and need to build from that using APT. Or perhaps you have the desktop but not the Synaptic GUI.

Getting Started
If the Linux distribution has just been installed, or the package manager hasn’t been used in a while, it’s important to refresh the package manager before doing anything, to avoid problems associated with broken package headers. The refresh operation is performed using the ‘apt-get update’ command.
Also it’s a good idea to perform an upgrade to the system, as mainstream Linux distros can rapidly become outdated. There are two options for this:

$apt-get upgrade
$apt full-upgrade

Basic Command Set
There are actually several variations of the ‘apt‘ command.


Using ‘apt‘ on its own will display the simple command set.


As you can see, all the functions of a GUI-based APT package manager are
present. There is also a ncurses-based interface called ‘aptitude‘.


Getting Repo and Package Lists
You might want to view and backup a list of package repositories for the installation. This can be done simply by piping the output to a text file. e.g.

$apt-get update >> repo-list.default.txt

Each entry is in exactly the same format used for adding a new repo later, so it’s useful for sharing known good repository addresses between installations.
Another command will also show how many packages are available in the current set:

$apt list >> package-list.txt

Or, alternatively:
$apt-cache stats

What if we want to install a program from the list? We won’t always know the exact full name of a package for a given application, and this is where the ‘apt search [application]‘ command is useful.


APT Sources
Sooner or later you might want to add other repositories for the current installation, either because the defaults become outdated or to get packages that aren’t available in the defaults. To do this, we can edit the apt sources.

$apt edit-sources

Or edit the sources list file directly at /etc/apt/sources.list.
These cannot simply be URLs. A source must be entered in a certain format that’s something like:
deb http://site.example.com/debian distribution component

Broken Package Headers
This causes all kinds of problems with apt. To fix this, we remove the package and source headers in /var/lib/apt/lists, then repopulate the directory.

#rm /var/lib/apt/lists/* -vf
#apt-get update

The APT Shell
An optional add-on is the APT Shell, listed as the ‘aptsh’ package. I haven’t found it useful, as it provides more or less the same thing as the command options.

Further Information
The man and info pages are always a good place to start for the apt commands. For anyone who wants more in-depth information on how the package manager works, documentation can be downloaded and viewed by installing the apt-doc package. This will place a set of text and HTML files in /usr/share/doc/apt-doc/, and these can be viewed in the command line using the lynx browser.