Introduction to APT Package Manager
APT (Advanced Package Tool) is how you install, update, and remove software on Ubuntu. Understanding how it works — not just which commands to type — helps you diagnose broken installs, manage dependencies, understand where packages come from, and keep a clean system over time.
What APT does and why it matters
Installing software on Ubuntu without apt means downloading tarballs, compiling from source, manually resolving dependencies, and then having no automated way to apply security updates. APT solves all of these problems by maintaining a list of available packages from trusted repositories, resolving dependency chains automatically, and providing a single command to keep every installed package up to date.
sudo apt install nginx
│
▼
APT queries the package cache (local index)
│
▼
Resolves dependencies:
nginx depends on nginx-core, libpcre3, libssl3, zlib1g, ...
│
▼
Downloads .deb packages from the repository mirror
│
▼
Calls dpkg to extract and install each package
│
▼
Registers nginx as installed in the dpkg database
│
▼
Runs post-install scripts (creates user, starts service, etc.)apt vs dpkg
| Tool | Level | Use for | Example |
|---|---|---|---|
dpkg | Low-level | Install/query a single .deb file; does NOT resolve deps | dpkg -i package.deb |
apt | High-level | Install from repos with full dependency resolution | apt install nginx |
apt-cache | Query only | Search and inspect packages without installing | apt-cache show nginx |
In practice, you almost always use apt. Use dpkg when you have a .deb file downloaded directly (e.g., Google Chrome, VS Code) and dpkg -l to query what is installed.
Essential apt commands
# Update the local package index from all configured repositories
# Always run this before installing anything
sudo apt update
# Install a package
sudo apt install nginx
# Install multiple packages at once
sudo apt install nginx mysql-server php-fpm
# Install without asking for confirmation
sudo apt install -y nginx
# Update all installed packages to their latest versions
sudo apt upgrade
# Full upgrade: may remove packages to resolve upgrade conflicts
sudo apt full-upgrade
# Remove a package (keep config files)
sudo apt remove nginx
# Remove a package AND its config files
sudo apt purge nginx
# Remove packages that were installed as dependencies and are no longer needed
sudo apt autoremove
# Clean the downloaded package files from the local cache
sudo apt clean
# Combined: update, upgrade all, and clean up in one command
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
How APT repositories work
APT downloads packages from repositories. The repository list is in /etc/apt/sources.list and /etc/apt/sources.list.d/*.list.
# View the current repository list
cat /etc/apt/sources.list
Example output
deb http://archive.ubuntu.com/ubuntu noble main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu noble-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu noble-security main restricted universe multiverse
The key parts of a repository line:
deb— binary packages (what you install)http://archive.ubuntu.com/ubuntu— the repository URLnoble— the Ubuntu codename (jammy=22.04, noble=24.04)main— officially supported packagesrestricted— officially supported but with non-free licensesuniverse— community-maintained packagesmultiverse— non-free software
# See all configured repositories (including .list.d files)
grep -r "^deb" /etc/apt/sources.list /etc/apt/sources.list.d/
APT package cache
When you run sudo apt update, APT downloads package metadata from each repository and stores it locally. This is the package cache. Without updating this cache, APT does not know about new package versions or newly available packages.
# Check when the package cache was last updated
stat /var/cache/apt/pkgcache.bin
# Check the size of the downloaded package cache
du -sh /var/cache/apt/archives/
# Clear the downloaded package files (free disk space)
sudo apt clean
# Clear only old versions of packages
sudo apt autoclean
💡 TIP: If you see "404 Not Found" errors when running
apt update, a repository URL has moved or a non-LTS release has reached end of life and been archived. Check the repository line in/etc/apt/sources.list.d/and update the URL or remove the stale entry.
Searching and inspecting packages
# Search for a package by name
apt search nginx
# Search with exact name match
apt show nginx
# Show all information about a package (version, deps, description)
apt-cache show nginx
# Show package dependencies
apt-cache depends nginx
# Show what depends on a package (reverse deps)
apt-cache rdepends --installed nginx
# List all installed packages
dpkg -l
# Check if a package is installed
dpkg -l nginx | grep -E "^ii"
# ii = installed, rc = removed (config remains), un = not installed
# Find which package owns a file
dpkg -S /usr/sbin/nginx
Example: checking if nginx is installed
$ dpkg -l nginx | grep -E "^ii"
ii nginx 1.24.0-2ubuntu7 amd64 high performance web server
APT output explained
When you run sudo apt upgrade, reading the output helps you understand what is changing:
sudo apt upgrade
Example output
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be upgraded:
linux-headers-generic linux-image-generic nginx
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 45.2 MB of archives.
After this operation, 1,024 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Key lines to read: which packages are being upgraded (check for surprises), how much disk space is needed, and whether any packages are being removed unexpectedly.
Conclusion
The APT workflow on Ubuntu is always: sudo apt update first (refresh the cache), then sudo apt install or sudo apt upgrade (act on fresh data). Run sudo apt autoremove regularly to clean up unused dependency packages. Use apt show and apt-cache depends to understand what a package does and what it pulls in before you install it.
FAQ
Why should administrators understand Introduction to APT Package Manager?+
Because this topic affects planning decisions, server lifecycle, compatibility, support expectations, or how you reason about Ubuntu systems before making operational changes.
Do I need a lab for this topic?+
A lab is useful for checking commands and seeing the concept on a real Ubuntu machine, but the main value is understanding the decision, tradeoff, or system behavior clearly.
How should I use this knowledge in production?+
Use it to make better choices, document why those choices were made, and avoid rushed changes that ignore support windows, compatibility, stability, or operational risk.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support