The Advanced Package Tool (APT) is a high-level package management system used in Debian-based Linux distributions, including Ubuntu, Kali Linux, and Raspberry Pi OS. It provides an easy interface to interact with the dpkg
package manager and handles dependency resolution automatically.
Before installing or upgrading packages, update the package list:
apt update
- Fetches the latest package information from the repositories.
To upgrade all installed packages to their latest versions:
apt list --upgradable
apt upgrade -y
- The
-y
option automatically accepts prompts.
To perform a full upgrade (includes removing obsolete packages if necessary):
apt full-upgrade -y
- Similar to
apt upgrade
, but can handle dependency changes and remove obsolete packages.
Alternatively, you can upgrade the entire system:
apt dist-upgrade -y
- Similar to
apt full-upgrade
; it handles changing dependencies and can remove obsolete packages.
To install a package:
apt install package_name -y
Example:
apt install nginx -y
apt remove package_name -y
Example:
apt remove nginx -y
apt remove --purge package_name -y
To remove packages that were automatically installed as dependencies but are no longer needed:
apt autoremove -y
To display detailed information about a package:
apt show package_name
Example:
apt show nginx
To list all installed packages:
apt list --installed
To count the number of installed packages:
apt list --installed | wc -l
apt depends package_name
Examples:
apt depends vlc
apt depends nginx
APT stores downloaded package files (.deb
) in /var/cache/apt/archives/
. To clean up and remove these cached files:
apt autoclean
To reinstall a package without removing its dependencies:
apt reinstall package_name
- Useful when a package is corrupted or misconfigured.
If you encounter issues with broken dependencies:
apt --fix-broken install
To force reconfiguration of packages that have not been properly configured:
dpkg --configure -a
If APT is locked by another process and you need to unlock it:
rm /var/lib/dpkg/lock
rm /var/lib/dpkg/lock-frontend
- Caution: Ensure no other package managers are running before removing lock files.
The /etc/apt/sources.list
file contains a list of software repositories from which APT fetches packages. You can edit this file to add or modify repositories.
- Debian Sources Generator (GitHub): https://debgen.github.io/ or https://debgen.xyz/
- Debian Wiki on Sources List: https://wiki.debian.org/SourcesList
To edit the sources list:
vim /etc/apt/sources.list
Example:
Default Debian 12 (Bookworm) sources.list
:
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
-
Verify Debian Version:
cat /etc/os-release
-
Replace placeholders in
sources.list
with your actual Debian version (e.g.,bullseye
,buster
).
If you encounter GPG signature errors when updating packages due to missing keys, you can add the missing keys:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys KEY_ID
- Replace
KEY_ID
with the actual key identifier.