Home Debian 15 Useful APT Command Examples for Debian, Ubuntu & Mint

15 Useful APT Command Examples for Debian, Ubuntu & Mint

Brief: This article guide walks us through the use of the Linux apt command with practical examples for effective package management in a Debian-based system.

Before Ubuntu 16.04, Debian-based Linux distributions like Ubuntu and Linux Mint made use of the ‘apt-get‘ command for package management.

The ‘apt‘ command came into the picture because ‘apt-get‘ was perceived as way too low level. The differences between these two commands are well explained in the following article:

What is APT?

Advanced Package Tool, more frequently called APT, is a collection of command-line programs used to install, remove, query, update and manage software packages on Debian and Debian-based distributions such as Ubuntu and Linux Mint through the use of official system repositories or third-party repositories that hold collections of software packages.

How to Use APT Command in Debian, Ubuntu, and Linux Mint

The usage of ‘apt‘ commands in Debian-based Linux distributions can be broken down into the following subsections.

apt update – Update Software Packages

The apt update command is used to update the local repository cache with software package metadata (information about the latest software versions available) and displays the list of all packages available for upgradation.

$ sudo apt update 
Update Software Packages
Update Software Packages

Three lines are likely to show up during this command execution:

  • Hit – Implies no package version changes.
  • Ign – package version info is ignored due to file retrieval error or version mismatch.
  • Get – Implies availability of new package version and downloads the package version information which makes it possible to, later on, install the package.

apt upgrade – Upgrade Installed Software Packages

The apt upgrade command is used to upgrade all available software packages presently installed on the system to the latest versions. Also, note during the upgrade process the newer packages will be installed if needed to satisfy dependencies, but existing packages will never be removed.

$ sudo apt upgrade
Upgrade Software Packages
Upgrade Software Packages

apt update and apt upgrade – What is the Difference?

The apt update command only retrieves the latest version info on the installed package and the apt upgrade command uses this version info to download and install data needed to upgrade the already existing package.

It, therefore, makes sense to jointly run the two commands as:

$ sudo apt update && sudo apt upgrade -y
Upgrade System Packages
Upgrade System Packages

apt full-upgrade – Upgrade Packages with Dependencies

The apt full-upgrade command is used to upgrade all installed packages and get rid of redundant or no-longer-required packages. The full-upgrade is usually performed at the distribution release’s life cycle end.

$ sudo apt full-upgrade
Upgrade Software Packages with Dependencies
Upgrade Software Packages with Dependencies

apt install – Install New Packages

The apt install command is used to install new software packages from the repository.

$ sudo apt install tree

If you are unsure of the package name, the [Tab] key to auto-complete the package name after keying in the first few letters. You will be provided with package name suggestions that exist.

Install New Packages
Install New Packages

apt install – Install Multiple Packages

The apt install command is also used to install multiple packages at the same time as shown.

$ sudo apt install tree treil
Install Multiple Packages
Install Multiple Packages

apt install – Install Package Without Upgrading

The apt install command with --no-upgrade option avoids the installed package from being upgraded.

$ sudo apt install tree --no-upgrade
Install Package Without Upgrading
Install Package Without Upgrading

apt install – Upgrade Installed Package

The apt install command with --only-upgrade option only upgrades the packages that are already installed, and does not install new packages.

$ sudo apt install tree --only-upgrade
Install Package Upgrades
Install Package Upgrades

apt install – Install Specific Package Versions

The Debian-based repository always avails the latest package version for installation. However, to install a specific version for project compatibility or something else, implement:

$ sudo apt install tree=2.0.2-1
Install Specific Package Versions
Install Specific Package Versions

apt remove – Remove Installed Package

The apt remove command removes an already installed package from the system without removing any configuration files created by the package.

$ sudo apt remove tree
Remove Installed Package
Remove Installed Package

Note that after running the ‘apt remove‘ command, it’s only the package binaries that are removed. Re-installing this package reuses the already existing configuration files. The ‘apt purge‘ command removes both the package binaries and its configuration files.

apt purge – Remove Package with Configuration Files

The apt purge command completely removes a package together with its configuration files.

$ sudo apt purge tree
Remove Package With Configuration
Remove Package With Configuration

apt search – Search New Packages

It is always a good idea to search for a package before installing it. The apt search command retrieves all packages with the specified search term.

$ sudo apt search tree
Search New Packages
Search New Packages

apt show – Show Package Information

To view package content like description, sources, download size, installation size, and dependencies, implement:

$ apt show tree
Show Package Info
Show Package Info

apt list – List Installed and Upgradable Packages

The apt list commands display information about all available, installed, and upgradeable packages.

$ sudo apt list --upgradable     [List Upgradable Packages]
$ sudo apt list --installed      [List Installed Packages]
$ sudo apt list --all-versions   [List Package Versions]
Show Installed Packages
Show Installed Packages

apt autoremove – Remove Packages No Longer Required

Sometimes the Debian-based system needs some clean-up routine to free up space from packages that are not being used by the system. Unlike apt-get which uses clean and autoclean commands, apt uses the autoremove command to achieve this objective.

$ sudo apt autoremove 
Remove Unwanted Packages
Remove Unwanted Packages

The apt autoremove command gets rid of libraries and packages automatically installed during the installation of a targeted package but the system finds these libraries and packages somewhat useless.

apt edit-sources – Edit Package Sources List File

The apt edit-sources command opens the /etc/apt/sources.list file contains info links on the packages’ location prior to their installation, update, and removal. Do not add, remove, or modify the content of this file unless you 100% understand what you are doing or have Linux system administration experience.

$ sudo apt edit-sources
Open Package Sources File
Open Package Sources File

Choose a preferred editor to open the file:

/etc/apt/sources.list File
/etc/apt/sources.list File

Changes on these /etc/apt/sources.list files are implemented during the next system update.

Conclusion

This guide on using ‘apt‘ commands with examples should guide you toward the mastery of the Linux command-line environment on a Debian-based Linux distribution.

Did we miss any important apt command examples? or if you have any extra tips, please share them in the comments below.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.