Linux apt Command: Manage Packages on Debian and Ubuntu

apt is an interactive command on Debian and Ubuntu-based systems used to search, install, remove, and upgrade packages from repositories. First, check if your distribution belongs to this family with cat /etc/os-release.

apt update fetches the latest package lists from the repositories and does not upgrade installed programs. apt upgrade reviews and applies updates for installed packages. When installing or removing packages, check the list of packages that change due to dependencies and the source repository. For scripts, apt-get is recommended considering output and operational stability.

Basic syntax

apt [options] command [packages...]

The installed implementations and options may vary depending on the distribution. Check the description of the current system with man apt.

Examples

Updating package information

Fetches the latest package information from the configured repositories. It does not actually upgrade programs.

sudo apt update

Searching and checking package information

Check the name, description, version, and source of installable candidates.

apt search nginx
apt show nginx

Package Installation

Proceed after reading and confirming the plan to add or remove dependencies.

sudo apt install nginx

Reading package information before installation

apt show checks the version, dependencies, description, etc. of a package as seen in the APT repository. Whether it is installed and the candidate version need to be checked separately.

apt show bash

Some examples of output format (versions vary depending on the distribution and timing):

Package: bash
Version: ...
Depends: ...
Description: GNU Bourne Again SHell

apt update only fetches the package list and does not upgrade installed packages. Before installation, check the candidate version and repository with apt policy package-name, and read and approve the list of dependency changes and deletions suggested by apt install. apt-get, which provides a stable interface, may be more suitable for automated scripts.

Stale repository metadata can give an outdated installation candidate, so refresh package lists with sudo apt update before installing. Refreshing lists is separate from upgrading. If apt upgrade holds packages back, review dependency changes and potential removals before choosing another operation.

Main Options and Format

Options/Format Description
update Update the package list of the repository.
search / show Search for a package or check detailed information.
install / remove Install or remove packages.
upgrade Apply possible upgrades to installed packages.
autoremove Suggest and remove automatically installed packages that are no longer needed.

Precautions when using

Security updates will not be installed with just apt update. Review the list of changes or removals before upgrade or autoremove, and prepare backups and a restart plan for important systems. Do not arbitrarily add repositories from unknown sources or disable signature verification.

Frequently Asked Questions

What is the difference between apt update and apt upgrade?

update downloads the package lists from the repositories, and upgrade upgrades the installed packages based on that information.

Official Documentation

You can check the exact behavior of the options and the differences by implementation in the official apt documentation.