Linux

APT in Ubuntu: A Complete Package Management Guide

This guide thoroughly explains how to effectively use APT—Ubuntu's primary package management tool. You'll learn to search for, install, update, and remove software from official repositories, as well as perform basic system maintenance.

Updated at February 17, 2026
15-30 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04 LTSUbuntu 22.04 LTSUbuntu 24.04 LTSUbuntu derivatives (Linux Mint, Pop!_OS)

Introduction / Why This Is Needed

APT (Advanced Package Tool) is the standard and most powerful software management tool for Debian-based distributions such as Ubuntu. It automatically resolves dependencies, ensures system integrity, and allows you to work with thousands of packages from official repositories.

In this guide, you will gain practical skills for working with APT via the command line. You will be able to confidently install, update, and remove software, as well as keep your system clean—an essential skill for any Ubuntu administrator or advanced user.

Requirements / Preparation

  • Operating System: Ubuntu 20.04 LTS or newer, or any derivative distribution (Linux Mint, Pop!_OS, elementary OS).
  • Access Permissions: Most operations (installation, update, removal) require superuser privileges (sudo).
  • Internet Connection: Required to download package information and the packages themselves.
  • Basic Knowledge: Comfort with the terminal (opening, navigation, simple commands).

Basic Package Operations

Step 1: Update the Package Cache (apt update)

Before any installation or update operation, always update the local package list cache. This forces APT to fetch the latest information about versions and new packages from the configured repositories.

sudo apt update

What happens: APT contacts the servers specified in /etc/apt/sources.list and the /etc/apt/sources.list.d/ directory, downloads Packages.gz files, and updates its local database. Without this step, the system will work with outdated data.

⚠️ Important: apt update does not update the packages installed on your system. It only updates the list of available versions for installation.

Step 2: Search and Install a Package (apt search / apt install)

Searching for a Package

If you don't know the exact package name, use keyword search in descriptions and names:

apt search <keyword>

Example: apt search video editor will show packages where the words "video" and "editor" appear in the description or name.

Installing a Package

To install, use the install command. APT automatically calculates and installs all necessary dependencies.

sudo apt install <package_name1> <package_name2>

Example: sudo apt install vlc git will install the VLC media player and the Git version control system.

💡 Tip: You can specify multiple packages in a single command. APT processes them all in one run.

Step 3: Updating and Removing Software

Updating Packages

  • Update a specific package:
    sudo apt install <package_name>
    

    If a newer version of this package exists in the repositories (after apt update), the install command will upgrade it.
  • Update all packages with updates:
    sudo apt upgrade
    

    This command upgrades all installed packages to the latest available versions, without removing any packages or installing new ones (except new dependencies).
  • Full system upgrade (including removal/installation):
    sudo apt full-upgrade
    

    Similar to upgrade, but more aggressive. It may remove packages if necessary to satisfy new dependencies. Use with caution on production servers.

Removing a Package

  • Remove a package, keeping configuration files:
    sudo apt remove <package_name>
    

    Configurations will remain in the system (/etc/), allowing you to preserve settings if you reinstall later.
  • Purge a package (including configs):
    sudo apt purge <package_name>
    

    Or (more modern syntax):
    sudo apt remove --purge <package_name>
    

    This completely removes all files belonging to the package, including configuration files.

Step 4: System Cleanup and Freeing Up Space

Over time, the APT cache (/var/cache/apt/archives/) accumulates .deb files from already installed packages. "Orphaned" dependencies may also remain after removals.

Clean the Download Cache

Removes all .deb files from the cache, except the very latest download of each package.

sudo apt clean

This is the most radical and space-freeing method. The next time you install a package, its .deb file will need to be downloaded again.

Clean Obsolete Cache Files

Removes only those .deb files from the cache for which there is no corresponding package version in the repositories anymore (i.e., obsolete versions).

sudo apt autoclean

A safer option than clean.

Remove Unnecessary Dependencies

Automatically finds and suggests removing packages that were installed automatically as dependencies but are no longer needed by any remaining installed packages.

sudo apt autoremove

Recommended practice: Periodically (once a month) run sudo apt update && sudo apt upgrade && sudo apt autoremove.

Verifying the Result

  1. Check package status: Find out if a package is installed and its version.
    apt list --installed | grep <package_name>
    

    Or for a specific package:
    apt show <package_name>
    
  2. Check for available updates: After apt update, see which packages can be upgraded.
    apt list --upgradable
    
  3. Check operation history: APT maintains a log at /var/log/apt/history.log. You can view it to see which packages were installed, upgraded, or removed.
    less /var/log/apt/history.log
    

Possible Issues

Error: "E: Could not get lock /var/lib/dpkg/lock-frontend"

Symptom: The apt command is interrupted with a lock error. Cause: Another package manager process (e.g., apt, apt-get, dpkg, unattended-upgrades) is already running. Solution:

  1. Wait 1-2 minutes if, for example, a background update is in progress.
  2. Find and terminate the process (carefully!):
    sudo killall apt apt-get dpkg
    
  3. If the problem persists, check if unattended-upgrades is running. You can temporarily stop the service: sudo systemctl stop unattended-upgrades.

Error: "E: Unable to locate package "

Symptom: APT cannot find a package with the specified name. Cause:

  1. You did not run sudo apt update after adding a new repository.
  2. The package is in a repository that is not enabled by default (e.g., universe, multiverse).
  3. The package has a different name (search via apt search). Solution:
  4. Run sudo apt update.
  5. Enable missing repositories via sudo add-apt-repository universe (or multiverse, restricted).
  6. Clarify the exact package name.

Error: "E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a'"

Symptom: The installation/removal process was interrupted (e.g., due to power loss or forced terminal closure). Solution: Run the recovery command; it will complete the interrupted package configuration.

sudo dpkg --configure -a

After it completes successfully, try your apt command again.

F.A.Q.

What's the difference between the apt, apt-get, and apt-cache commands?
What to do if you get the 'Unable to locate package' error when installing a package?
How to safely update only a specific package instead of the entire system?
Why is the 'autoremove' command needed and when is it safe to run?

Hints

Update package cache
Search for and install a package
Update and remove software
System cleanup

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community