keepcalculator

06 Numbers and Powers

apt-get vs apt: Key Commands and Usage

Card No. 06·28184 · Updated · Standard formula, shown below

Average pace 5.00 min/km
Average speed
12.00 km/h
Result
Finish time
50 min
You entered
Distance
10 km
You entered
You enter
Finish time, Distance
You get
Average pace, Average speed
Rounding
2 dp

apt-get and apt are command-line tools for managing software packages on Debian-based Linux systems. apt-get is the older, lower-level tool; apt is a newer front-end that combines the most common apt-get and apt-cache commands into a simpler interface. Both interact with the same package database, so you can use either to install, update, and remove software.

What Is apt-get?

apt-get is the original package management tool from the Advanced Package Tool (APT) project. It has been part of Debian since the late 1990s and is still the backbone of package management on Debian, Ubuntu, and their derivatives. It performs the core operations: updating the package index, installing and removing packages, and upgrading the system. It is designed for scripting and automation because its output is stable and its behavior is predictable across versions.

Common apt-get commands include:

  • apt-get update – refreshes the list of available packages from configured repositories.
  • apt-get upgrade – installs newer versions of all currently installed packages.
  • apt-get install <package> – installs a package and its dependencies.
  • apt-get remove <package> – removes a package but leaves configuration files.
  • apt-get purge <package> – removes the package and its configuration files.
  • apt-get autoremove – removes packages that were installed as dependencies but are no longer needed.

What Is apt and How Does It Differ?

apt was introduced in Ubuntu 16.04 and Debian 8 as a more user-friendly interface. It combines the most frequently used functions of apt-get and apt-cache into one command. For example, apt install, apt remove, and apt update work the same as their apt-get counterparts, but apt search and apt show replace the need for separate apt-cache commands.

The main differences are:

  • Output formatting: apt adds color and progress bars, making it easier to read.
  • Additional commands: apt includes list, search, show, and edit-sources, which are not in apt-get.
  • Stability: apt-get’s output is stable for scripts; apt’s output may change between versions.
  • Underlying behavior: apt automatically runs some steps (like updating the package list) that apt-get does not.

For everyday use, apt is sufficient and recommended. For scripting, apt-get is the safer choice because its interface is guaranteed not to change.

Frequently Used apt and apt-cache Commands

Here are the commands you will use most often, grouped by purpose.

Updating and Upgrading

  • sudo apt update – refreshes the package index (same as apt-get update).
  • sudo apt upgrade – upgrades all upgradable packages.
  • sudo apt full-upgrade – like upgrade, but may remove or install new packages to resolve dependencies.

Installing and Removing

  • sudo apt install <package> – installs a package.
  • sudo apt remove <package> – removes a package, keeping config files.
  • sudo apt purge <package> – removes package and config files.
  • sudo apt autoremove – cleans up orphaned dependencies.

Searching and Viewing Information

  • apt search <keyword> – finds packages matching a keyword.
  • apt show <package> – shows detailed info about a package.
  • apt list --installed – lists all installed packages.
  • apt list --upgradable – lists packages that have available upgrades.

These apt commands replace the older apt-cache search and apt-cache show.

When to Use apt vs apt-get

For interactive use, apt is the recommended choice because it is more readable and includes helpful hints (like suggesting apt autoremove). For scripts, cron jobs, or any automated process, use apt-get because its output is consistent and less likely to break your parsing.

Some system administrators prefer apt-get even interactively because they are used to it, but there is no technical reason to avoid apt for manual work. The two tools share the same underlying libraries and package database, so mixing them is perfectly safe.

Common Problems and How to Solve Them

“Unable to locate package�

This usually means the package list is outdated. Run sudo apt update first. If the package still isn’t found, it may not be in your configured repositories, or the repository may need to be added.

“Could not get lock /var/lib/dpkg/lock�

Another package manager process is running. Wait for it to finish, or if it crashed, remove the lock file with sudo rm /var/lib/dpkg/lock (but only if you are sure no other apt process is active).

Broken dependencies

Run sudo apt --fix-broken install to repair dependency issues. This often happens after a partial upgrade or manual package removal.

Upgrade asks to remove packages

This is normal with full-upgrade when dependency changes require removing obsolete packages. Review the list and confirm only if you understand the changes.

apt-cache: The Package Query Tool

apt-cache is a separate command that queries the local package cache. It does not modify the system. Its most useful commands are:

  • apt-cache search <keyword> – finds packages by name or description.
  • apt-cache show <package> – displays detailed info like version, size, and dependencies.
  • apt-cache policy <package> – shows installed and candidate versions, and which repository they come from.
  • apt-cache depends <package> – lists a package’s dependencies.
  • apt-cache rdepends <package> – lists packages that depend on the given package.

In modern apt, you can use apt search, apt show, and apt policy instead, which are aliases for the apt-cache versions.

Frequently Asked Questions

Is apt faster than apt-get?

No, both are equally fast because they use the same underlying libraries and download from the same repositories. The perceived speed difference is only due to apt’s progress bars and colored output.

Can I mix apt and apt-get in the same session?

Yes, you can. They share the same package database and lock files, so running apt install and then apt-get remove works fine. Just do not run two package manager commands simultaneously.

Why does apt sometimes say “The following packages were automatically installed and are no longer required�?

This happens after you remove a package that was a dependency of another package that is no longer installed. Run sudo apt autoremove to clean them up and free disk space.

What is the difference between upgrade and full-upgrade?

upgrade only upgrades packages without removing any installed packages. full-upgrade may remove or install new packages if needed to satisfy dependencies. For most users, upgrade is safe; full-upgrade is useful when upgrading between release versions.

Do I need to run apt update before every install?

Not always, but it is good practice. The package list is only refreshed when you run apt update. If the list is old, you might not see the latest versions or new packages. Running update before install ensures you get the most current available version.

How do I see all available versions of a package?

Use apt-cache policy <package>. It shows the installed version, the candidate (default) version, and a list of all versions available in your repositories, with their priority.

Related

Formula used
in t | Finish time | min | 50 | 0
in d | Distance | km | 10 | 0 | 100000
out pace | Average pace | min/km | t / d | 2
out speed | Average speed | km/h | d / (t / 60) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →