Linux apt-get Command: Run APT Package Operations in Scripts

apt-get is an APT command used in Debian and Ubuntu-based systems to install, remove, and update packages. Its functions overlap with the user-oriented apt, but apt-get is more suitable for automation scripts.

What is the apt-get command?

Updating the repository list is done with update, and updating installed packages is done with upgrade. install handles the requested package and its necessary dependencies together. -s is useful for simulating package changes, and -y automatically agrees to confirmation prompts, so using it without review can be risky.

Basic syntax

apt-get [options] command [packages...]

The implemented features and options may vary depending on the distribution. Check the current system description with man apt-get.

Examples

Updating the repository list

Fetches updated metadata for installation candidates.

sudo apt-get update

Previewing the upgrade plan

Check the plan for installing, keeping, or removing packages without actually making changes.

apt-get -s upgrade

Package Installation

Check the list of changes without the automatic approval option before installing.

sudo apt-get install curl

Simulation Before Actual Changes

apt-get -s install simulates the installation process to show which packages will be added or upgraded. It does not perform an actual installation.

apt-get -s install curl

The format of the lines you can see in the output (packages and versions may vary depending on your environment):

Inst curl (...)
Conf curl (...)

Inst indicates items to be installed or upgraded, Conf indicates items to be configured. Dependency packages may also be displayed, so do not just look at the final summary; check the items that will be deleted or replaced. You should also distinguish between apt-get update, which updates the package list, and apt-get upgrade, which upgrades the installed packages.

Main Options and Format

Options/Format Description
update Update the package list.
install / remove Install or remove packages.
upgrade / full-upgrade Apply updates. full-upgrade may remove packages to resolve dependencies.
-s, --simulate Simulate the execution result without making actual changes.
-y, --yes Automatically agree to confirmation questions. Review the change plan in advance.

Precautions when using

If you always use -y, you may miss unexpected dependency changes. Since full-upgrade can remove packages, perform a simulation and backup before proceeding on systems where services are critical. In scripts, you should also check repository trust and error exit codes.

Frequently Asked Questions

Do I have to use apt-get instead of apt?

apt is convenient for interactive use. For automated scripts, prioritize apt-get considering operational and output compatibility.

Official Documentation

The exact behavior of the options and the differences depending on the implementation can be found in the official documentation related to apt-get.

More in This Category
Linux systemctl Command: Manage systemd Services

Linux systemctl Command: Manage systemd Services

Learn how to manage systemd Services with the Linux systemctl command, including practical examples, key options, and important precautions.

Linux join Command: Combine Files by a Common Field

Linux join Command: Combine Files by a Common Field

Learn how to combine Files by a Common Field with the Linux join command, including practical examples, key options, and important precautions.

Linux head Command: Display the Beginning of a File

Linux head Command: Display the Beginning of a File

Learn how Linux head prints the first lines or bytes of files and pipelines, labels multiple inputs, excludes a trailing portion, and handles multibyte data.

Linux xargs Command: Pass Standard Input as Command Arguments

Linux xargs Command: Pass Standard Input as Command Arguments

Learn how to pass Standard Input as Command Arguments with the Linux xargs command, including practical examples, key options, and important precautions.

Linux nmap Command: Scan Authorized Hosts and Ports

Linux nmap Command: Scan Authorized Hosts and Ports

Learn how to scan Authorized Hosts and Ports with the Linux nmap command, including practical examples, key options, and important precautions.

Linux pkill Command: Signal Processes by Name

Linux pkill Command: Signal Processes by Name

Learn how to signal Processes by Name with the Linux pkill command, including practical examples, key options, and important precautions.

Linux split Command: Divide Large Files into Smaller Parts

Linux split Command: Divide Large Files into Smaller Parts

Learn how to divide Large Files into Smaller Parts with the Linux split command, including practical examples, key options, and important precautions.

Linux ssh-keygen Command: Generate SSH Keys and Inspect Fingerprints

Linux ssh-keygen Command: Generate SSH Keys and Inspect Fingerprints

Learn how to generate SSH Keys and Inspect Fingerprints with the Linux ssh-keygen command, including practical examples, key options, and important precautions.

Linux tac Command: Print Lines in Reverse Order

Linux tac Command: Print Lines in Reverse Order

Learn how Linux tac prints records from last to first, handles multiple files and custom separators, and helps inspect recent log entries in reverse order.

Linux pacman Command: Manage Packages on Arch Linux

Linux pacman Command: Manage Packages on Arch Linux

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