Package Management
Objective
Install, update, remove, and manage software packages on Debian/Ubuntu using APT, understand repositories, and find package information.
Tools & Technologies
aptapt-getdpkgapt-cachesnap/etc/apt/sources.list
Key Commands
apt update && apt upgradeapt install nginxapt remove --purge nginxdpkg -l | grep nginxapt-cache search termArchitecture Overview
sequenceDiagram
participant U as User
participant APT as APT
participant REPO as Repository\n(mirrors)
participant DPKG as dpkg
participant FS as Filesystem
U->>APT: apt install nginx
APT->>REPO: Download package index
REPO-->>APT: Package metadata
APT->>REPO: Download nginx.deb + deps
REPO-->>APT: .deb files
APT->>DPKG: Install packages
DPKG->>FS: Extract files
FS-->>U: nginx installed
Step-by-Step Process
01
Update & Upgrade
Always update the package index before installing or upgrading.
sudo apt update # refresh package lists
sudo apt upgrade # upgrade installed packages
sudo apt full-upgrade # upgrade + remove blocking pkgs
sudo apt dist-upgrade # similar, handles dependencies better
sudo apt autoremove # remove unused dependencies
02
Install & Remove
Install individual packages or remove them cleanly.
sudo apt install nginx
sudo apt install -y curl wget git vim # -y skips confirmation
sudo apt remove nginx # remove but keep config
sudo apt remove --purge nginx # remove including config
sudo apt autoremove # clean up orphaned deps
03
Search & Inspect
Find packages and get information about them.
apt-cache search nginx # search by keyword
apt-cache show nginx # package details
apt-cache depends nginx # list dependencies
dpkg -l | grep nginx # check if installed
dpkg -L nginx # list installed files
where-is nginx # find binary location
04
Manage Repositories
Add third-party repositories for software not in the main repo.
# View current repos
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
# Add a PPA (Ubuntu)
sudo add-apt-repository ppa:deadsnakes/ppa
# Add a repo manually
echo 'deb https://example.com/repo focal main' | sudo tee /etc/apt/sources.list.d/myrepo.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys KEYID
sudo apt update
Challenges & Solutions
- apt update ≠ apt upgrade — update refreshes lists, upgrade installs updates
- Removing without --purge leaves config files that may cause confusion on reinstall
Key Takeaways
- apt list --upgradable shows pending updates
- Hold a package at current version: apt-mark hold nginx