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.









