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 pwd Command: Print the Current Working Directory

Linux pwd Command: Print the Current Working Directory

Learn how to use the Linux pwd command to print the logical or physical absolute path of the current working directory, with essential options, practical examples, output interpretation, and common troubleshooting tips.

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.

Linux bunzip2 Command: Decompress bzip2 Files

Linux bunzip2 Command: Decompress bzip2 Files

Learn how to decompress bzip2 Files with the Linux bunzip2 command, including practical examples, key options, and important precautions.

Linux cat Command: Display and Concatenate File Contents

Linux cat Command: Display and Concatenate File Contents

Learn how to use the Linux cat command to display text files, concatenate multiple files, number lines, reveal hidden characters, and avoid unsafe redirection mistakes.

Linux find Command: Search Files by Name, Type, Size, and Time

Linux find Command: Search Files by Name, Type, Size, and Time

Learn how to search with Linux find by name, file type, size, and modification time, combine expressions, run commands safely, and verify targets before deletion.

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 passwd Command: Change a User Password

Linux passwd Command: Change a User Password

Learn how to change a User Password with the Linux passwd command, including practical examples, key options, and important precautions.

Linux whatis Command: Show One-Line Command Descriptions

Linux whatis Command: Show One-Line Command Descriptions

Learn how to use the Linux whatis command to display concise descriptions of commands and manual pages, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux top Command: Monitor Processes in Real Time

Linux top Command: Monitor Processes in Real Time

Learn how to monitor Processes in Real Time with the Linux top command, including practical examples, key options, and important precautions.

Linux tail Command: View the End of a File and Follow Logs

Linux tail Command: View the End of a File and Follow Logs

Learn how to use the Linux tail command to view the last lines of a file and follow log updates in real time, with essential options, practical examples, output interpretation, and common troubleshooting tips.