Kahibaro
Discord Login Register

APT (Debian/Ubuntu)

Understanding APT on Debian/Ubuntu

APT (Advanced Package Tool) is the package management layer used by Debian, Ubuntu, and many derivatives (Linux Mint, Pop!\_OS, etc.). It works on top of .deb packages and a repository system, and is normally used via commands like apt, apt-get, and apt-cache.

This chapter focuses on:

You should already know what package management is in general from the parent chapter.


The APT Command Family

On Debian-based systems, you’ll commonly see three related tools:

For interactive use as a human user:

Examples in this chapter will primarily use apt, and mention the older equivalents where useful.


Updating Package Information

Before installing or upgrading software, update APT’s local package index:

sudo apt update

What this does:

Typical pattern:

sudo apt update
sudo apt upgrade

Older equivalents:

Searching for Packages

To find packages by name or description:

apt search <keyword>

Examples:

apt search firefox
apt search image editor

This may list many results. Each line usually looks like:

To get detailed information about a specific package:

apt show <package>

Example:

apt show curl

This shows:

Older equivalents:

Installing Packages

To install a package:

sudo apt install <package>

Examples:

sudo apt install curl
sudo apt install vlc

You can install multiple packages at once:

sudo apt install git build-essential cmake

APT will:

If you know a package is already up to date but not installed, apt will simply install it; you don’t need a separate “download” step.


Removing and Purging Packages

To remove a package but keep its configuration files:

sudo apt remove <package>

Example:

sudo apt remove vlc

To remove a package and its configuration files:

sudo apt purge <package>

Example:

sudo apt purge vlc

Purging is useful if:

You can also use --purge with remove:

sudo apt remove --purge <package>

Older equivalent:

Upgrading Installed Software

After sudo apt update, there are a few ways to upgrade:

`apt upgrade`

sudo apt upgrade

`apt full-upgrade` (or `dist-upgrade`)

sudo apt full-upgrade

Older equivalence:

For normal desktop use, apt upgrade regularly and apt full-upgrade occasionally (e.g., after a distribution release) is common.


Cleaning Up Downloaded Packages

APT caches downloaded .deb files in /var/cache/apt/archives. Over time, this can consume disk space.

Useful cleanup commands:

Remove unneeded package files

sudo apt autoclean

Clear the entire package cache

sudo apt clean

Removing Automatically Installed Dependencies

When you install a package, APT may pull in dependencies that are no longer needed after you remove the original package.

To remove these “orphaned” dependencies:

sudo apt autoremove

Viewing Installed Packages

To list all installed packages:

apt list --installed

To check if a specific package is installed:

apt list --installed | grep <package>

or:

dpkg -l | grep <package>

Basic pattern:

Managing Repositories (Basics)

Detailed repository configuration is handled elsewhere, but you should know how APT relates to repositories.

APT reads its repository configuration from:

A typical entry in sources.list looks like:

deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse

You normally:

After any change to repositories, always run:

sudo apt update

so APT knows about the new or changed sources.


Installing from Local `.deb` Files

Sometimes software is distributed as a standalone .deb file (e.g., downloaded from a website).

To install a local .deb with APT dependency handling:

sudo apt install ./package-name.deb

Note the ./ – it tells APT to treat it as a local file, not a repo package.

Older method:

sudo dpkg -i package-name.deb
sudo apt -f install

Here, dpkg -i may leave unmet dependencies; apt -f install fixes them. Using apt install ./file.deb is simpler and preferred.


Lock Files and Parallel Package Managers

APT uses a lock file to prevent multiple package operations running at the same time. Common error:

:::text
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process XXXX (...)

Typical causes:

Basic handling:

  1. Wait a bit – the other process might finish.
  2. Close any GUI “Software Updater” or “Software Center” windows.
  3. Don’t remove lock files manually unless you really know what you’re doing.

Check with:

ps aux | grep apt

and wait for system package tasks to complete.


Common APT Errors and How to Approach Them

Some frequent issues and typical beginner-level responses:

“Unable to locate package”

Example:

:::text
E: Unable to locate package packagname

Possible causes:

What to try:

“Failed to fetch” / Network errors

Example:

:::text
Failed to fetch http://...

Likely causes:

What to try:

Partial or broken installations

You might see messages about:

Often, running:

sudo apt --fix-broken install

can resolve dependency issues by:

Practical Everyday Workflows

Here are some common “recipes” you’ll use with APT:

Install a program

sudo apt update
sudo apt install <program>

Upgrade your system (routine)

sudo apt update
sudo apt upgrade

Remove a program completely

sudo apt remove <program>
sudo apt autoremove

If you also want to remove configs:

sudo apt purge <program>
sudo apt autoremove

Find and inspect a package

apt search <keyword>
apt show <package>

When to Use `apt-get` Instead of `apt`

While apt is suitable for most tasks, you might still see apt-get:

Useful apt-get subcommands parallel to apt:

For a beginner working interactively, stick with apt unless you have a specific reason not to.


Summary

On Debian/Ubuntu and derivatives, APT is your main tool for:

Comfort with these commands will cover the vast majority of software-management tasks you’ll do on Debian- and Ubuntu-based systems.

Views: 22

Comments

Please login to add a comment.

Don't have an account? Register now!