Kahibaro
Discord Login Register

2.5.2 APT (Debian/Ubuntu)

Introduction to APT on Debian and Ubuntu

APT, which stands for Advanced Package Tool, is the primary command line package management system used on Debian, Ubuntu, and many of their derivatives. It works with .deb packages and communicates with software repositories that your system knows about. In this chapter the focus is on the everyday commands you need to install, remove, and update software using APT on beginner friendly systems like Ubuntu, Linux Mint, and Debian.

APT works with administrative privileges. Commands that change installed software typically require sudo. A mistake in package management can remove important system components, so always read what APT plans to do before confirming.

Basic APT Workflow

APT has a common workflow that you will repeat often. The system maintains a local cache of available packages, then you request changes, and APT resolves dependencies and applies them.

The typical pattern looks like this, using sudo because system wide software changes require administrator rights:

  1. Update the list of available packages with sudo apt update.
  2. Install or remove packages with commands like sudo apt install or sudo apt remove.
  3. Apply pending upgrades with sudo apt upgrade.

You usually run these commands inside a terminal. When APT needs your confirmation it shows what will be installed, updated, or removed, then asks you to confirm with Y or N.

Updating Package Information

APT does not constantly query the internet. Instead, it stores a list of available packages and versions that it downloads from configured repositories. This list can become outdated, so you need to refresh it periodically.

To update the package list you use:

bash
sudo apt update

This connects to each configured repository and downloads updated package information. The command does not upgrade any installed software, it only refreshes the metadata. In practice you will usually run sudo apt update before installing new software or performing upgrades, so that APT has fresh information about the newest versions.

If apt shows errors related to network access or repositories, package operations that depend on new information can fail. You should resolve those errors before continuing.

Installing Packages

To install software you use the install subcommand followed by one or more package names. For example, to install the text based web browser lynx, you would run:

bash
sudo apt install lynx

APT checks the package list, finds lynx, and then resolves any dependencies that lynx requires. It shows a summary of what will be installed and how much disk space will be used. After you confirm, APT downloads and installs all required .deb files, then configures them.

You can install multiple packages in a single command by listing them separated by spaces:

bash
sudo apt install curl wget htop

If a package is already installed, APT will usually either keep it as is or upgrade it to the latest available version when you run install. If you attempt to install a package that does not exist in the repositories, APT informs you that it cannot find the package.

Always check the list of packages APT plans to remove as part of an install operation. If APT proposes to remove important system components, stop and investigate before confirming.

Removing and Purging Packages

To remove software you use the remove subcommand. For example, to remove lynx:

bash
sudo apt remove lynx

This removes the package’s program files but often leaves behind configuration files in case you want to reinstall later and keep your settings.

If you want to remove both the package and its system wide configuration files, use purge:

bash
sudo apt purge lynx

Purging is stronger than removal, yet even purge does not delete user specific configuration files stored in your home directory. Those remain until you remove them manually.

Sometimes removing a package leaves behind automatically installed dependencies that are no longer needed. You can ask APT to clean up these unused dependencies with:

bash
sudo apt autoremove

This command removes packages that were automatically installed to satisfy dependencies and are no longer required by any installed package.

Upgrading Installed Software

Refreshing the package list with apt update does not actually upgrade your software. To apply updates to installed packages you use upgrade or related commands.

The standard way to update installed packages to the newest versions that fit current dependency constraints is:

bash
sudo apt upgrade

APT examines all upgradable packages, lists them, and asks for confirmation. This command upgrades packages without removing any installed ones. If an upgrade requires removing something, apt upgrade will usually hold back the conflicting packages instead.

On recent Debian and Ubuntu systems you will sometimes see sudo apt full-upgrade recommended. This command can install, upgrade, and remove packages as needed to complete all upgrades. It is more aggressive. If you use it, read the list of packages to be removed very carefully.

You can also upgrade a single package by installing it again:

bash
sudo apt install --only-upgrade package-name

Or simply:

bash
sudo apt install package-name

if you already know it is installed and a newer version is available.

Searching for Packages

If you know you want some functionality but do not know the exact package name, APT can search its package list. The search subcommand looks for packages by name and short description.

For example, to search for packages related to editor:

bash
apt search editor

You do not need sudo to search, because this does not change the system. The output shows package names, their short descriptions, and an indication of whether they are installed.

Searching can return many results. It is common to narrow down your search term or pipe the results through a pager like less. For example:

bash
apt search editor | less

This lets you scroll through the results more comfortably.

Viewing Package Information

Before installing a package, you might want more details about what it does, what version is available, and which dependencies it has. For that you use the show subcommand.

For example:

bash
apt show lynx

This prints detailed information including:

Package version
Short and long description
Dependencies and recommended packages
Repository origin

This information helps you decide whether a package is appropriate and also where it comes from. On systems with multiple repositories or third party sources, apt show can reveal which repository provides a given version.

Managing Cached Packages and Cleanup

APT stores downloaded .deb files in a local cache so that it can reuse them if you reinstall or downgrade. Over time this cache can become large. You can remove unneeded cached files with:

bash
sudo apt clean

This deletes all cached package files, freeing disk space. It does not affect installed software.

A related command, sudo apt autoclean, removes only cached packages that can no longer be downloaded because they are outdated. This is a lighter cleanup and is often safe to run regularly.

Combining autoremove and autoclean allows you to keep your system tidy by removing unnecessary packages and old cached files that are no longer useful.

Handling Installation Prompts and Configurations

Some packages ask configuration questions during installation, such as which service to use or which options to enable. APT hands these questions to a system called debconf. In most desktop scenarios, you can accept the default answers. The installer shows options and highlights the default choice.

When upgrading, if a package’s configuration file has been modified, APT might ask whether to keep your version or replace it with the package maintainer’s version. If you have not edited the file manually, accepting the maintainer’s version is usually safe. If you have custom changes, you may want to keep your version.

If APT asks about replacing a configuration file you have changed, choose carefully. Replacing it might break your custom setup. Keeping it might prevent new defaults from taking effect.

For absolute beginners, it is usually best to leave most advanced configuration choices at their default unless you follow specific instructions from reliable documentation.

APT vs apt-get and Other APT Tools

On modern Debian and Ubuntu systems you will find several related commands such as apt, apt-get, and apt-cache. All are front ends to the same underlying APT libraries but have different interfaces and histories.

The apt command is designed to be more user friendly for interactive use. It offers concise output and combines common tasks such as searching and showing information. For everyday work in a terminal, especially as a beginner, apt is usually the right choice.

The older apt-get and apt-cache commands are still widely used in scripts and older documentation. They remain fully functional, but for manual use on a current system, the apt interface is typically more convenient.

You may also see graphical front ends that use APT behind the scenes. These tools are covered in other parts of the course. From the perspective of package management, they perform the same operations that you can do manually with apt at the command line.

Common APT Usage Patterns

On a Debian or Ubuntu system, day to day package management often comes down to a few repeated patterns in the terminal.

When you want to install new software, you first refresh the package list and then install:

bash
sudo apt update
sudo apt install package-name

When you want to keep your system up to date, you regularly run:

bash
sudo apt update
sudo apt upgrade

When you want to remove unused software and clean up, you run:

bash
sudo apt remove package-name
sudo apt autoremove
sudo apt autoclean

And when you want to find out what a package is or whether something exists, you use:

bash
apt search keyword
apt show package-name

By practicing these commands on a Debian or Ubuntu based system, you will become comfortable managing software from the command line with APT.

Views: 72

Comments

Please login to add a comment.

Don't have an account? Register now!