Package Management

Package management in Debian-based system.

Table of Contents

Check Kali version

grep VERSION /etc/os-release

Advanced Package Tool (APT)

Advanced Package Tool (apt) is a set of tools to manage packages or applications on Debian-based systems.

Update the local APT cache

APT packages information (available packages, versions, descriptions, etc.) is cached locally in a database for faster results.

sudo apt update

Upgrade packages

When working in a virtual machine, take a snapshot before upgrading in case something goes wrong.

Update the APT cache

sudo apt update

List packages that can be upgraded.

apt list --upgradable

Upgrade all packages to the latest version

If an upgrade for a package requires the removal of an installed package the upgrade for this package isn’t performed.

sudo apt update && sudo apt upgrade

Same as upgrade, but will remove currently installed packages if this is needed to upgrade the system as a whole. Upgrade distribution.

sudo apt update && sudo apt -y full-upgrade

Upgrade one package to the latest version

sudo apt update && sudo apt upgrade <package name>

Install packages

Also installs recursively all the package dependencies.

Search for a package

Searches in the package description (not the name) in the cache.

apt-cache search <keyword>
apt-cache search xss

Show package information (description, version, etc.)

apt show <package name>

Install a package

sudo apt install <package name>

Remove packages

Remove a package with its data – keep user configuration files

sudo apt remove <package name>

Remove a package with its data – delete configuration files

sudo apt remove --purge <package name>

Cleans the packages and install script in /var/cache/apt/archives/

apt clean

Delete all packages not currently installed (less than clean alone)

apt autoclean

Remove orphaned packages that are no longer needed

sudo apt autoremove --purge

Space problem

Space problem when upgrading:
Error: You don’t have enough free space in /var/cache/apt/archives/.

du -h /var | grep -e "G\s"

Cleanup journals

sudo journalctl --rotate
sudo journalctl --vacuum-size=100M

Change journal configuration, set “SystemMaxUse=100M”

sudo nano /etc/systemd/journald.conf
sudo systemctl restart systemd-journald

Repositories

sudo nano /etc/apt/sources.list

For Kali Linux:

Use HTTPS instead of HTTP to bypass some firewall or antivirus blocking the download (error File has unexpected size).

#deb http://http.kali.org/kali kali-rolling main contrib non-free
deb https://http.kali.org/kali kali-rolling main contrib non-free
deb-src http://http.kali.org/kali kali-rolling main contrib non-free
# Enable Bleeding Edge
echo "deb http://http.kali.org/kali kali-bleeding-edge main contrib non-free non-free-firmware" | sudo tee /etc/apt/sources.list.d/kali-bleeding-edge.list

GPG Keys

GPG keys are used to sign software packages and repositories. This ensures that the packages you download are genuine and have not been tampered with. GPG keys have an expiration date as a security measure.

Kali no longer accepts binary GPG keyrings (.gpg) for repo signing. It now expects ASCII‑armored (.asc) keys or dearmored keyrings referenced explicitly.

Add the GPG key (converting the former .gpg format):

curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/docker.gpg > /dev/null

Add the GPG key (.asc format):

sudo curl -fsSL https://packages.microsoft.com/keys/microsoft.asc -o /usr/share/keyrings/microsoft.asc

Add the repository (.gpg or .asc):

echo 'deb [signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian stretch stable' > /etc/apt/sources.list.d/docker.list
echo "deb [signed-by=/usr/share/keyrings/microsoft.asc] https://packages.microsoft.com/repos/code stable main" | sudo tee /etc/apt/sources.list.d/vscode.list

Add signing key for the Kali repository

To fix for error “Warning: An error occurred during the signature verification”. See A New Kali Linux Archive Signing Key (Kali).

sudo wget https://archive.kali.org/archive-keyring.gpg -O /usr/share/keyrings/kali-archive-keyring.gpg

Add signing key for the Microsoft repository

When getting error:

Warning: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. OpenPGP signature verification failed: https://packages.microsoft.com/debian/9/prod stretch InRelease: Sub-process /usr/bin/sqv returned an error code (1), error message is: Missing key EB3E94ADBE1229CF, which is needed to verify signature.

sudo wget https://packages.microsoft.com/keys/microsoft.asc -O /usr/share/keyrings/microsoft-prod.gpg
sudo cp /usr/share/keyrings/microsoft-prod.gpg /etc/apt/trusted.gpg.d/microsoft-prod.gpg

For installing Kali tools on a Debian machine

sudo nano /etc/apt/sources.list
... other debian reposiries ...
# Kali repositories
deb [trusted=yes] https://http.kali.org/kali kali-rolling main contrib non-free
deb-src [trusted=yes] http://http.kali.org/kali kali-rolling main contrib non-free

Fix:
Error: The repository ‘http://http.kali.org/kali kali-rolling InRelease’ is not signed.
Error: The following signatures couldn’t be verified because the public key is not available

sudo apt install gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys ED444FF07D8D0BF6

Via proxy

Bypass blocking using a proxy.

On Kali – SSH Dynamic Port Forwarding

ssh -q -D6666 user@proxyserver
[password]

Add a proxy in APT proxy configuration

sudo nano /etc/apt/apt.conf.d/12proxy
Acquire::http::proxy "socks5h://127.0.0.1:6666";

Update & upgrade as usual

sudo apt update && sudo apt upgrade

dpkg

dpkg is the software at the base of the package management system in Debian-based systems and is also used by apt. dpkg is used to install, remove, and provide information about .deb packages.

Install *.deb apps

dpkg does not automatically install package dependencies.

sudo dpkg -i /root/Downloads/teams_1.3.00.958_amd64.deb

Delete old linux images, frees space in /boot

dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]' | xargs sudo apt-get -y purge

YUM

Red Hat-based Linux systems

yum install <package name>
yum install nano
yum install gcc-c++
yum install python3-devel

Repositories

sudo nano /etc/yum.conf

RPM

Red Hat-based Linux systems