Operations 7 min read

Mastering APT: Essential Commands for Ubuntu & Debian Package Management

Learn how to efficiently manage Debian-based packages on Ubuntu and other Linux distributions using APT, covering updating the package index, upgrading system and individual packages, installing and removing software, handling dependencies, and leveraging powerful commands like list, search, and show for comprehensive system maintenance.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering APT: Essential Commands for Ubuntu & Debian Package Management

Overview

APT is a command‑line utility for installing, updating, removing, and managing .deb packages on Ubuntu, Debian, and related Linux distributions. It combines the most common commands from apt-get and apt-cache with user‑friendly defaults, but scripts should still use the older tools for backward compatibility.

Updating the Package Index

The APT package index is a local database of all packages available from enabled repositories. Refresh it before any upgrade or installation: sudo apt update Running this command fetches the latest metadata from the repositories.

apt update output screenshot
apt update output screenshot

Upgrading Packages

Regular upgrades keep the system secure. To upgrade all installed packages to their newest versions: sudo apt upgrade This command upgrades packages without removing any that require additional deletions. To upgrade a single package, specify its name:

sudo apt upgrade package_name

Full Upgrade

Use full-upgrade when you want APT to handle package removals that are necessary for a complete system upgrade: sudo apt full-upgrade Exercise caution, as this may uninstall packages.

Installing Packages

Install a package from the repositories with: sudo apt install package_name Multiple packages can be installed at once by separating them with spaces: sudo apt install package1 package2 To install a local .deb file, provide its full path:

sudo apt install /full/path/file.deb

Removing Packages

Remove an installed package: sudo apt remove package_name Multiple packages can be removed together: sudo apt remove package1 package2 Use purge instead of remove to delete configuration files as well:

sudo apt purge package_name

Cleaning Unused Dependencies

After uninstalling packages, orphaned dependencies may remain. Clean them up with:

sudo apt autoremove

Listing Packages

List all available packages:

sudo apt list
apt list output
apt list output

Filter the list with grep to find a specific package: sudo apt list | grep package_name Show only installed packages:

sudo apt list --installed
installed packages list
installed packages list

List packages that can be upgraded:

sudo apt list --upgradable
upgradable packages
upgradable packages

Searching Packages

Search the repository for a package name or keyword:

sudo apt search package_name

Showing Package Information

Before installing or removing a package, view detailed information such as dependencies, size, and source:

sudo apt show package_name
apt show output
apt show output

Conclusion

Effective package management is a core skill for Linux system administrators. Mastering APT commands—update, upgrade, install, remove, list, search, and show—enables you to keep systems secure, resolve dependencies, and maintain a clean environment. For more details, consult the manual with man apt.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem AdministrationAPTcommandspackage management
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.