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, always update the package list:
apt update
This fetches the latest package information from the repositories.
To upgrade all installed packages to their latest versions:
apt list --upgradable
apt upgrade -y
To perform a full upgrade (includes removing obsolete packages if necessary):
apt full-upgrade -y
To upgrade the entire system while handling dependency changes and removing obsolete packages:
apt dist-upgrade -y
To install a package:
apt install package_name
Example:
apt install nginx
To remove a package but keep its configuration files:
apt remove package_name
Example:
apt remove nginx
To completely remove a package along with its configuration files:
apt purge package_name
Example:
apt purge nginx
If you don't know the exact package name, you can search for it:
apt search package_name
Example:
apt search nginx
To display detailed information about a package:
apt show package_name
Example:
apt show nginx
To list all installed packages:
apt list
To count the installed packages:
apt list | wc -l
To list only installed packages:
apt list --installed
To count installed packages:
apt list --installed | wc -l
To check dependencies of a package:
apt depends package_name
Examples:
apt depends vlc
apt depends nginx
To remove packages that were automatically installed as dependencies but are no longer needed:
apt autoremove -y
APT caches downloaded package files in /var/cache/apt/archives/
. To clear them and free up space:
apt clean
To remove only outdated package files:
apt autoclean
To reinstall a package without removing its dependencies (useful for fixing corrupted or misconfigured packages):
apt reinstall package_name
Example:
apt reinstall nginx
The /etc/apt/sources.list
file contains a list of software repositories from which APT fetches packages. It can be edited to add or modify repositories.
- SimplyLinux Debian Generator
- Debian Sources Generator (GitHub) (Alternative)
- Debian Wiki on Sources List
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
Ensure the correct Debian version is in /etc/os-release
:
cat /etc/os-release
Replace bookworm
with the correct version (e.g., bullseye
, buster
) in sources.list
.
Add missing keys:
apt install debian-archive-keyring