Lab 16: Package Management — apt and dpkg

Objective

Manage software with apt and dpkg: install, update, search, inspect packages, and understand the APT repository system. This is how you add tools to Linux servers and keep them secure with patches.

Time: 30 minutes | Level: Foundations | Docker: docker run -it --rm ubuntu:22.04 bash


Step 1: Understanding Installed Packages with dpkg

dpkg -l | head -6

📸 Verified Output:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                    Version                                 Architecture Description
+++-=======================-=======================================-============-========================================================================
ii  adduser                 3.118ubuntu5                            all          add and remove users and groups
# Count installed packages
dpkg -l | grep -c '^ii'

📸 Verified Output:

105

💡 ii = correctly installed. rc = removed but config files remain. un = not installed. The status flags tell you exactly what's on the system.


Step 2: Inspect a Package

📸 Verified Output:

📸 Verified Output:

📸 Verified Output:


Step 3: Update Package Lists

📸 Verified Output:

💡 apt-get update downloads the list of available packages from Ubuntu servers — it does NOT install or upgrade anything. Always run this before installing new packages to get the latest versions.


Step 4: Install a Package

📸 Verified Output:

📸 Verified Output:


Step 5: Search for Packages

📸 Verified Output:

📸 Verified Output:


Step 6: Package Dependencies

📸 Verified Output:

💡 APT automatically resolves and installs dependencies. This is why apt install nginx might install 10+ packages — it includes all the libraries nginx needs to run.


Step 7: Remove and Purge Packages

📸 Verified Output:


Step 8: Capstone — Security Package Audit Script

📸 Verified Output:


Summary

Command
Purpose

apt-get update

Refresh package lists

apt-get install pkg

Install package

apt-get remove pkg

Remove (keep configs)

apt-get purge pkg

Remove + delete configs

apt-get upgrade

Upgrade all installed packages

apt-cache show pkg

Package information

apt-cache search term

Search available packages

dpkg -l

List installed packages

dpkg -S /path/file

Which package owns this file?

dpkg -L package

Files installed by package

Last updated