Exercise 05 — Package Management¶
Navigation: ← Exercise 04 | Exercises Index | Next → Exercise 06 Note: 05 — Package Management
Before You Start¶
Read Note 05 first.
These exercises use APT (Ubuntu/Debian). If you're on Fedora or RHEL, substitute apt with dnf — the concepts are identical.
You'll need internet access and sudo privileges.
Exercise 5.1 — Update Your Package List¶
Always do this before installing anything.
Step 1: Update the package list:
You'll see output like this:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [128 kB]
Fetched 3,456 kB in 4s (864 kB/s)
57 packages can be upgraded. Run 'apt list --upgradable' to see them.
This downloaded updated package information. Nothing was installed yet — it's just refreshing the catalogue.
Step 2: See which packages have available updates:
What is
2>/dev/null?2>redirects error messages./dev/nullis a "black hole" that discards anything sent to it. This hides a harmless warning thatapt listalways prints. You'll often see this pattern when you want to suppress noise.
Step 3: Count how many packages can be upgraded:
Reflect: Why is it important to run apt update before apt install? What happens if you skip it?
Exercise 5.2 — Research a Package Before Installing¶
It's good practice to look at what you're about to install.
Step 1: Search for packages related to "network scanner":
You'll see a list of packages with their names and descriptions.
Step 2: Get detailed information about nmap (a popular network scanner):
Expected output (abbreviated):
Package: nmap
Version: 7.80+dfsg1-2build1
Depends: libc6, liblinux-procfs-perl, ...
Description: The Network Mapper
Nmap is a utility for network exploration or security auditing.
...
Read the Depends: line — that's the list of other packages nmap needs to work. APT will install all of these automatically.
Step 3: Check if a package is already installed:
If it's installed, you'll see Status: install ok installed. If not, you'll see an error.
Exercise 5.3 — Install, Use, and Remove a Package¶
Step 1: Install tree — a handy tool that shows directories visually:
-y automatically answers "yes" to the confirmation prompt. You'll see it downloading and installing.
Step 2: Try it out:
Expected output (something like):
/home/jahid/linux-practice/
├── logs
│ └── app.log
├── notes
│ ├── day1.txt
│ └── day2-renamed.txt
└── scripts
3 directories, 3 files
See how much clearer this is than ls -R? That's the value of tree.
Step 3: Find out where tree was installed:
Expected output:
which shows the path to the executable file of a command.
Step 4: List every file the tree package installed:
You'll see a list of files — the binary, man page, etc. All of these will be removed when you uninstall.
Step 5: Remove tree:
Step 6: Verify it's gone:
Expected output:
Or you might see:
Step 7: Remove leftover dependencies:
This removes any packages that were installed automatically to support tree but are no longer needed by anything else.
Exercise 5.4 — Install a Useful Tool and Explore It¶
Now install something you'll actually keep and use.
Step 1: Install htop — a better version of top:
Step 2: Open it:
You'll see a colorful, real-time view of your processes and resources. Click on a column header to sort by it. Press q to quit when you're done exploring.
Step 3: Install ncdu — an interactive disk usage explorer:
Step 4: Use it to explore your home directory:
Navigate with arrow keys, press Enter to open a directory, press q to quit. This makes it easy to find what's eating up disk space.
Exercise 5.5 — Investigate an Installed Package with dpkg¶
dpkg gives you low-level package information.
Step 1: List all installed packages (there will be many):
Each line follows this format:
The ii at the start means "installed, install ok". Other codes: rc means the package was removed but config files remain.
Step 2: Find all installed packages with "python" in the name:
You'll likely see several Python-related packages — Python is used by many system tools.
Step 3: Find which package owns a specific file:
Expected output:
This tells you ls comes from the coreutils package. Try it with other commands too:
Step 4: Check if nginx is installed (it probably isn't yet):
If nginx isn't installed, you'll see an error message. That's expected — we use nginx in the mini-projects later.
Exercise 5.6 — Upgrade a Package¶
Step 1: Upgrade all packages with available updates:
This is safe to run — it only upgrades existing packages, never removes them. The output shows you exactly what's being upgraded.
Step 2: After upgrading, check if a reboot is needed:
Some kernel updates only take effect after a reboot. This file exists only when a reboot is required.
Challenge — Find, Install, Explore, Remove¶
Pick one package from this list that you find interesting:
| Package | What it does |
|---|---|
jq |
Pretty-prints and queries JSON data |
net-tools |
Classic network tools (ifconfig, netstat) |
dstat |
Live system resource stats |
bat |
A better version of cat with syntax highlighting |
fzf |
Fuzzy finder — interactive search for the terminal |
- Use
apt showto read about it before installing - Install it
- Find out where it installed its binary using
which - List the files it installed with
dpkg -L - Try using it with
--helpto understand basic usage - Remove it with
apt remove - Confirm it's gone with
which
Navigation: ← Exercise 04 | Exercises Index | Next → Exercise 06 Note: 05 — Package Management