Linucate
~ Linucate_

102.4 Use Debian package management

All Levels

Introduction

This lesson is about Debian-style package management.

The main question is:

How do you install, remove, inspect, and search packages on Debian-based systems?

What you should be able to do after this lesson:

  • Use dpkg for local package operations.
  • Use apt-get and apt-cache for repository-based work.
  • Find which package owns a file.
  • Read package status and dependency information.
  • Recognize /etc/apt/sources.list.

Two Layers: dpkg and apt

dpkg

This is the low-level Debian package tool. It works directly with .deb packages.

apt

This is the higher-level tool that works with repositories and dependency resolution.

Simple way to remember it:

dpkg works on package files; apt works on package sources and dependencies

Basic dpkg Commands

Install a local package

sudo dpkg -i package.deb

Important beginner note:

  • dpkg -i works directly on a local package file
  • if dependencies are missing, the package may not end up fully configured until you fix them

Remove a package but keep config files

sudo dpkg -r package-name

Remove a package and its config files

sudo dpkg -P package-name

Show package status

dpkg -s package-name

Show installation status in a package list

dpkg -l | head

List installed files from a package

dpkg -L package-name

Find which package owns a file

dpkg -S /usr/bin/ssh

Representative example output:

openssh-client: /usr/bin/ssh

What this shows:

  • the package name is on the left
  • the owned file path is on the right

Basic apt-get Commands

Update package lists

sudo apt-get update

Install a package

sudo apt-get install package-name

Upgrade packages

sudo apt-get upgrade

Remove a package

sudo apt-get remove package-name

apt-cache: Search and Inspect

Search by keyword

apt-cache search nginx

Representative example output:

nginx - small, powerful, scalable web/proxy server
nginx-common - small, powerful, scalable web/proxy server - common files

What this shows:

  • apt-cache search returns matching package names and short descriptions
  • one search term can return multiple related packages

Show package information

apt-cache show nginx

Check version and repository info

apt-cache policy nginx

Show dependencies

apt-cache depends nginx

Package Sources

Repository definitions often live in:

/etc/apt/sources.list
/etc/apt/sources.list.d/

The exam idea is simple:

  • these files tell APT where packages come from

dpkg-reconfigure

This tool lets you re-run package configuration questions for some packages.

Example:

sudo dpkg-reconfigure tzdata

Reinstall and Package Integrity Awareness

LPIC expects more than just install/remove basics.

Useful ideas to recognize:

  • a package can be installed but misconfigured
  • a file can exist even when the package is not currently installed
  • dependency information matters when troubleshooting broken package states

Common reinstall pattern:

sudo apt-get install --reinstall package-name

Common package questions:

  • Is it installed?
  • What version is it?
  • What files does it contain?
  • What does it depend on?

A Safe Mental Workflow

When using Debian package tools:

  1. apt-get update
  2. inspect package info if needed
  3. install or upgrade
  4. use dpkg when you need package-file details

Practice Step by Step

1) Find which package owns a file
  1. Run: dpkg -S /usr/bin/ssh
  2. Read the package name on the left.
2) Search for a package before installing it
  1. Update metadata: sudo apt-get update
  2. Search: apt-cache search editor
  3. Inspect a candidate: apt-cache show nano
3) Reconfigure an installed package
  1. Run: sudo dpkg-reconfigure tzdata
  2. Follow the prompts.

Cheat Sheet

  • dpkg -i = install a local .deb
  • dpkg -r = remove package, keep configs
  • dpkg -P = purge package and configs
  • dpkg -s = show package status
  • dpkg -L = list files from a package
  • dpkg -S <file> = find package owning a file
  • apt-get update = refresh package lists
  • apt-get install = install from repos
  • apt-get upgrade = upgrade packages
  • apt-cache search = search packages
  • apt-cache show = show package details
  • /etc/apt/sources.list = package source configuration
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.