The Ultimate Guide to Apt and Apt-Get Commands

Linuxapt Package

For many people entering into Debian/Ubuntu-based Linux distros for the firest time, package management may seem convoluted. Some tutorials tell you to use “apt,” others “apt-get,” and some really old or specific ones use “aptitude.” It’s high time to get down to the absolute minutiae and explain the “why, where, what, and how” of the strange and somewhat divided world in this little corner of the Linux universe.

If you are new to Linux, you may want to check out these useful Bash commands before heading to the terminal.

Defining Apt-Get, Apt, Aptitude, and DPKG

Regardless of all the small details that distinguish them, apt, apt-get, and aptitude are all just different calling cards for Debian’s package management system that interacts with online repositories. As if there weren’t enough of these already, there’s also one more package management tool in Debian or Ubuntu-based systems you might have heard of that deals with on-disk installations: dpkg.

DPKG is a tool that runs in the background every time you install a .deb package. Apt, Apt-get and Aptitude all use dpkg to install packages.

What’s Aptitude?

Aptitude is the nerve center of package management, acting as a front-end if you want to have a detailed look at all the packages your distro offers in its repositories and those that you’ve added. It’s also one of the few old-school clickable GUIs that run directly inside the terminal.

Linuxapt Aptitude

What Is APT?

Known as the Advanced Packaging Tool, APT is Debian’s solution to mainstreaming the process of removing, installing, searching for, and managing the various applications you install in the operating system. Every distro based on it uses APT, though not all implementations of APT are equal. We’ll get to this in a bit.

For now, it’s important to note that APT as a package manager is not the apt command. It instead encompasses a variety of APT-related commands like apt-get, apt-mark, and apt-cache.

Think of Aptitude as the interactive command center of all your package management and APT as the Swiss-army knife that lets you quickly perform simpler tasks related to installing, removing, and updating your packages and repositories.

What Distros Use APT?

If your distro is described as “Debian-based,” it uses the APT tool in one way or another. This includes but isn’t limited to:

  • Debian
  • Ubuntu
  • Linux Mint
  • MX Linux
  • Grml
  • Kali Linux
  • Tails
  • PureOS
  • Raspberry Pi OS
  • Elementary OS

There are many, many more distributions based on Debian, so if you’re using something that isn’t listed here, check whether the apt-get command works by simply typing it in your terminal. If your terminal returns a confused message about the command not existing, then you’re definitely not running anything touched by Debian or Ubuntu developers.

Apt-get vs. Apt

In many online tutorials involving the installation of a package, you’ll see apt-get and apt being used interchangeably as commands on Debian-based systems. When it comes to installing and removing stuff, there is indeed no difference which command you use. Just don’t confuse this for the two being versions of the other.

Remember how I said apt-get is simply one of a few other commands in the Advanced Packaging Tool? For someone who’s new to APT, it can be a little disorienting to have to memorize which commands are valid for apt-get, apt-mark, and apt-cache. For example, did you know that the command to search for a package is apt-cache search?

Linuxapt Cachesearch

What if all three of these commands’ most useful functions for day-to-day life were more uniform?

This is exactly what the apt command does by itself. These three letters, when typed into your terminal, act as a “wrapper” for the APT ecosystem, simplifying the process for people who spend much of their time scribbling at their terminals.

When searching for a package, apt search should mostly return the same results as apt-cache search.

Linuxapt Search 1

Instead of typing apt-cache search, apt-mark hold, and apt-get remove in your terminal, you can instead use apt search, apt hold, and apt remove.

APT is an ecosystem where both apt-get install and apt install are both valid options but behave a little differently. The simple apt is an application that wraps around the old-school APT commands to provide a simpler structure that’s more intuitive to users who don’t want to memorize a bunch of different commands to perform different tasks with their package managers.

In some distros like Ubuntu, the apt command is a separate application that will sometimes just execute one of the older commands with specific options enabled (like a progress bar when installing), making it appear more feature-rich to newer users who don’t want to complicate themselves with several obscure flags in the package manager.

Other distros like Linux Mint achieve the same thing by making a simple Python wrapper. To the end user, both will appear identical.

A Word on APT Flags

If you paid close attention to the images showing the outputs of both search commands, they show slightly different information, as the apt command grabs information about the status of the application in your system in addition to whatever apt-cache search puts out.

Now is probably a good time to explain what that “i” meant next to the package name in the output of apt search. It’s a flag placed by aptitude, the front-end of the Debian package tool.

Below is a list of flags you’ll see in your terminal and what they mean:

  • A – automatically installed, perhaps as part of a larger meta-package or the installation of the operating system itself.
  • B – the package is flagged as broken and must be reinstalled.
  • H – half-installed. The package needs to finish installing.
  • c – the package was removed, but its “ghost” lingers on in the form of configuration files. You can solve this by using apt-get purge or apt purge, followed by the name of the package with this flag.
  • p – package purged or was never installed.
  • v – the package is installed and is generically used by others to provide a function. For example, Firefox provides browsing capabilities that can be used by other applications, making it a virtual package.
  • i – this package is installed in your system.
  • h – there’s a hold on this package, preventing it from being updated to newer versions.

Not All APT Implementations Are Equal!

Before going any further into the topic of package management, it’s extremely important to note that the apt command may have more available arguments in one distro than it does in another. For example, Ubuntu lacks “hold” while Mint has it.

To fully take in what I’m saying here, we need to have a look at the Ubuntu and Mint listings for what arguments you can pass in apt and see the sheer chasm between the two.

The below image shows Ubuntu on my newly minted (pun intended) test-bed for tutorials.

Linuxapt Ubuntu

The following image shows Linux Mint.

Linuxapt Mint

By far, Mint has the most fleshed-out wrapper of all Debian-based distributions I’ve seen up until now. This isn’t surprising when you realize it was tailor-made by the community that maintains Mint to cater both to starters who just want to install their apps in peace with a short command and to the turbo-geeks who want to tune everything just the way they want with millimeter precision.

The Ultimate Guide to APT Commands

There’s no better way to understand the power of the APT package system than sinking your teeth into some important commands. The list will consist of APT commands followed by the apt simplification, where it’s applicable, in parentheses. If the simplification does not work in your particular distro, it’s either because yours hasn’t included it for some reason or you’re not running Mint’s behemoth of a wrapper. In that case, you can safely fall back on the vanilla command without losing too much.

Add a Repository

  • add-apt-repository – adds a new repository to your list of software sources from a package maintainer.

For example, if I want to add Lutris’s current repository for Mint 20, I can type either sudo add-apt-repository or sudo apt add-repository, followed by ppa:lutris-team/lutris. Each repository is unique, and most application developers that don’t have packages found in the official ones for your distro will include instructions that will point you to their own.

Clean & Autoremove

  • apt clean & apt autoremove – often used together, these two commands sweep out the dust in your system in the form of lingering install scripts and installation media you no longer need (clean), as well as automatically freeing your storage of packages that no one uses or depends on (autoremove).

Example: sudo apt autoremove && sudo apt clean will hoover all the unnecessary applications and cache files from your main drive in one single line in your terminal.

If you just want to remove a file, you can use the rm command instead or the dd command if you want to free up the disk usage space.

Changelog

  • apt changelog – spot the latest changes in a package.

Example: apt changelog brave-browser will tell me what the latest version of the Brave browser includes compared to its last revision.

Contains

  • apt contains – found only in Linux Mint and maybe a few other Ubuntu-derived distros, this command is what you use when you encounter a “file not found” kind of error in a program. With some luck, apt contains will find that file for you in some far-flung folder from an application you installed!

Example: apt contains gettext.sh will look for the application that contains the shell script for gettext. If you have gettext-base installed in your Mint distro, you should find the app that has it immediately!

Install & Reinstall

  • apt install – as the name implies, it installs a package. Passing the --reinstall flag will immediately reinstall your package.

Example of installing: sudo apt install firefox. Example of a Firefox reinstallation: sudo apt reinstall firefox. A more simple variant through the apt wrapper is sudo apt reinstall firefox.

If you prefer a graphical application to help you install applications, you can check out Synaptic Package Manger.

Remove (Uninstall)

  • apt remove – Another frequently used tool in the terminal cave-diver’s arsenal. This command will uninstall anything that was installed either by the APT ecosystem or the DPKG package manager.

Example: sudo apt remove grub-customizer.

Update, Upgrade & Hold

  • apt update – this command does not update the applications in your system. It simply refreshes the APT cache so that your system can compare the versions available in your repositories with what’s currently installed on your system. It’s checking for updates but not performing them.
  • apt upgrade – this will download updates to your packages that your system found if they are available. You generally don’t have to close anything that’s running to perform this.
  • apt hold/unhold/showhold – This series of commands manages your held applications. Holding a package tells your operating system not to update it in the future. With hold and unhold, you can initiate or cancel an update hold on an application. The showhold argument will list what you currently have on hold. If you can’t use this in your installed system, try apt-mark showhold instead!

Example: sudo apt hold pulseaudio. A word to the wise: holding updates on packages that others depend on may damage your system in the long term if you’re not certain what you’re doing.

Search & Show

  • apt search/show – This lovely pair of commands bonds well together. Use the first to find a package, then use show followed by the package’s full name to find out more details about it.

Example: sudo apt search gimp.

If you wish to read more on the intricacies of APT for your particular distro that may not have been covered here, their manuals are in the terminal. Just type man before the command without any further arguments, and press Enter.

Tip: you can also search the web from the terminal.

The Dreaded APT “command not found” Issue

If you can’t install anything on your terminal because APT just went poof and disappeared, this isn’t the end of the world. With a little bit of elbow grease, you’ll have your favorite package manager up and running.

First, if this is a new system, just double-check that it’s supposed to be using APT as a package manager. Fedora uses DNF/yum, Arch uses Pacman, Solus uses EOPKG, openSUSE uses zypper, and Mandriva uses urpmi. If your distro is not listed anywhere, you’ll have to look up its documentation on package management, usually found on the site where you got the distro in the first place.

Once you’re sure you’re in a Debian-based system and APT is indeed missing, it’s time to move on to the next step.

To walk you through this with a little extra stake in the matter, I am crippling my Ubuntu system and will not allow myself the easy escape of reinstalling the OS!

Linuxapt Cripple

The result is now either a “command not found” error or an inability to process the command.

Linuxapt Error

It’s time to go and find the appropriate APT package for our system and install it. Since we don’t have APT to work with, we can’t automatically download the dependencies either.

Luckily, Debian’s on-disk package manager (dpkg) is here to save the day! I downloaded the latest version of the apt package corresponding to my CPU architecture from Ubuntu’s main repo and ran dpkg -I on it to list the dependencies I needed to install. If you’re looking at that linked repository and can’t quite make heads or tails of it, look for “apt_x.xx” where “x” represents the latest version number. If you’re running a 64-bit system, download the “amd64” version. On 32-bit, download the “i386” version.

Linuxapt Dependencies

In my case, upon attempting to install the latest version of APT, the dependencies were all there but were not recent enough.

You discover these things when you type dpkg -i /path/to/your/apt/deb/file. Obviously, you need to replace that phony path I typed with whatever path corresponds to the .deb file you downloaded from the website.

Linuxapt Versionproblems

Instead of version 2.3.11, I chose to go for version 2.0.6, which is what is typically installed in Mint at the time of writing.

Linuxapt Success

After fiddling around with versions here and there, you’re going to eventually stumble upon one that works with your current setup. This is what happened to me. After typing sudo dpkg -i followed by this older package, it installed smoothly.

Generally, APT’s most dire dependencies are things your system wouldn’t be missing. However, since you’re missing APT, anything’s possible. In any case, if you find that you lack one of the dependencies listed after looking with dpkg -I as discussed earlier, have a look through the parent folders in the linked repository. They should be in their corresponding alphabetically-sorted folders.

Frequently Asked Questions

Are there unsafe APT commands?

Generally, if you type anything APT-related in your terminal, you should be aware of what that command is about to do. Before major updates, especially those where you install a new kernel, make a full backup of your system just to be safe.

All that aside, the commands you have to really be careful with are apt hold and apt full-upgrade/dist-upgrade. Holding may break your system until you lift your holds, especially if you’re doing it to dependencies of other applications. They may fall too far behind and not perform the functions those applications expect them to.

full-upgrade and dist-upgrade are only useful when your distro releases a new long-term version that you’d like to migrate to, but they will also potentially remove installed packages that you were accustomed to using. You’re generally in much safer territory by performing a normal apt upgrade, then doing an apt autoremove to clear out the packages truly gathering dust.

Is Apt better than Apt-get?

I know this is a tired statement, but it really does depend on what you’re doing. Are your fingers getting rug burn from typing so many commands? You may want to use apt as a shortcut if you don’t need something specific that apt-get would be more suitable for. In many ways, apt not only streamlines the package management process but also provides extra information as we saw earlier when comparing apt-get search to apt search.

However, if you’re not on Mint with its gargantuan argument list for apt that almost entirely renders apt-get superfluous, you may have to use apt-get to do some more niche tasks.

What's the difference between a repository and an app store?

To the day-to-day user, the differences are insignificant. Where they begin to part ways is in software “fungibility.” Linux has a very fluid software market, where users are presented with a sometimes-overwhelming amount of choices. Smartphone app stores are pretty much set in stone, and it’s hard to imagine users seeking alternatives.

At the same time, in theory, the personal package archives (PPAs) that people enjoy using in Ubuntu can be compromised and lead to the proliferation of malicious software by bad actors.

If there’s one thing to take away from this, it’s that decentralization comes with some responsibility on the part of the user. Make sure that the repositories you add to your distro are from sources you can trust and projects that have stood for a long time.

Image credit: All images by author.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Miguel Leiva-Gomez
Miguel Leiva-Gomez - Staff Writer

Miguel has been a business growth and technology expert for more than a decade and has written software for even longer. From his little castle in Romania, he presents cold and analytical perspectives to things that affect the tech world.