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.

What is the apt command?

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.

More in This Category
Linux du Command: Check File and Directory Disk Usage

Linux du Command: Check File and Directory Disk Usage

Learn how to use the Linux du command to measure and summarize disk space used by files and directories, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux apk Command: Manage Packages on Alpine Linux

Linux apk Command: Manage Packages on Alpine Linux

Learn how to manage Packages on Alpine Linux with the Linux apk command, including practical examples, key options, and important precautions.

Linux chgrp Command: Change a File's Group

Linux chgrp Command: Change a File's Group

Learn how to change a File's Group with the Linux chgrp command, including practical examples, key options, and important precautions.

Linux cmp Command: Compare Files Byte by Byte

Linux cmp Command: Compare Files Byte by Byte

Learn how Linux cmp compares two files byte by byte, reports the first mismatch, runs silently in scripts, limits ranges, and differs from diff and checksums.

Linux host Command: Look Up DNS Names and Addresses

Linux host Command: Look Up DNS Names and Addresses

Learn how to look Up DNS Names and Addresses with the Linux host command, including practical examples, key options, and important precautions.

Linux traceroute Command: Trace Routers on the Way to a Host

Linux traceroute Command: Trace Routers on the Way to a Host

Learn how to trace Routers on the Way to a Host with the Linux traceroute command, including practical examples, key options, and important precautions.

Linux df Command: Check Filesystem Free Space

Linux df Command: Check Filesystem Free Space

Learn how to check Filesystem Free Space with the Linux df command, including practical examples, key options, and important precautions.

Linux tee Command: Display and Save Pipeline Output

Linux tee Command: Display and Save Pipeline Output

Learn how to display and Save Pipeline Output with the Linux tee command, including practical examples, key options, and important precautions.

Linux Tutorial / Install and Update Packages with APT and DNF

Linux Tutorial / Install and Update Packages with APT and DNF

Compare APT on Debian or Ubuntu with DNF on Rocky Linux for searching, installing, updating, and removing packages, including repository and transaction checks.

Linux nohup Command: Keep a Command Running After Logout

Linux nohup Command: Keep a Command Running After Logout

Learn how to use the Linux nohup command to keep a command running after the terminal closes or the user logs out, with essential options, practical examples, output interpretation, and common troubleshooting tips.