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 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.

Linux Tutorial / Understand systemd Services, Boot, and Logs

Linux Tutorial / Understand systemd Services, Boot, and Logs

Understand Linux boot stages and systemd units, distinguish active services from boot enablement, and inspect current-boot logs with systemctl and journalctl.

Linux wget Command: Download Files from URLs

Linux wget Command: Download Files from URLs

Learn how to download Files from URLs with the Linux wget command, including practical examples, key options, and important precautions.

Linux printenv Command: Print Environment Variable Values

Linux printenv Command: Print Environment Variable Values

Learn how to use the Linux printenv command to print all environment variables or selected variable values, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux umask Command: Control Default File Permissions

Linux umask Command: Control Default File Permissions

Learn how to control Default File Permissions with the Linux umask command, including practical examples, key options, and important precautions.

Linux nc Command: Test TCP and UDP Connections

Linux nc Command: Test TCP and UDP Connections

Learn how to test TCP and UDP Connections with the Linux nc command, including practical examples, key options, and important precautions.

Linux umount Command: Unmount a Filesystem Safely

Linux umount Command: Unmount a Filesystem Safely

Learn how to unmount a Filesystem Safely with the Linux umount command, including practical examples, key options, and important precautions.

Linux htop Command: Explore Processes Interactively

Linux htop Command: Explore Processes Interactively

Learn how to explore Processes Interactively with the Linux htop command, including practical examples, key options, and important precautions.

Linux blkid Command: Find Block-Device UUIDs and Filesystem Types

Linux blkid Command: Find Block-Device UUIDs and Filesystem Types

Learn how to find Block-Device UUIDs and Filesystem Types with the Linux blkid command, including practical examples, key options, and important precautions.

Linux scp Command: Copy Files over SSH

Linux scp Command: Copy Files over SSH

Learn how to copy Files over SSH with the Linux scp command, including practical examples, key options, and important precautions.