apt (Advanced Package Tool) is the default package manager used on Ubuntu, Debian, and all other Debian-based Linux distributions. It’s the go-to method for installing packages from repository, and can also install a local DEB file. In this tutorial, you will learn how to use the apt
command for package management on Ubuntu and Debian Linux systems.
Installing a Package
Before installing a package, you should always fetch the latest repository information:
$ sudo apt update
Then, install a package with apt install
:
$ sudo apt install package_name
To install a local package (.deb
file):
$ sudo apt install ./package_name.deb
Upgrading Packages
To get a list of upgradable packages installed on your system:
$ sudo apt list --upgradable
To update all packages:
$ sudo apt upgrade
To update all packages and Linux kernel:
$ sudo apt full-upgrade
To remove lingering packages that are no longer needed:
$ sudo apt autoremove
One-liner to update the whole system:
$ sudo apt update && sudo apt -y full-upgrade && sudo apt -y autoremove
Getting Package Info
Retrieve information about a package:
$ apt show package_name
To list the installed packages in your system:
$ apt list --installed
Some packages rely on others in order to be installed and used. To list the dependencies of a certain package:
$ apt depends package_name
Searching for a Package
To search for a package:
$ apt search package_name
Removing and Purging Packages
The remove
command will uninstall a package, but leave behind configuration files and (sometimes) additional program data like user settings. The purge
command will uninstall a package and also remove all related configuration files and other data. If you don’t plan to reinstall the package, then purge
is the recommended option.
To remove a package:
$ sudo apt remove package_name
To purge a package:
$ sudo apt purge package_name
To remove the libraries and dependencies that are no longer needed:
$ sudo apt autoremove
Reinstalling a Package
To reinstall a package:
$ sudo apt --reinstall install package_name
apt vs. apt-get
dpkg
is the backend package management system for Debian-based distros. apt-get
and apt
are frontend commands that interact with dpkg
and extend its functionality. The apt-get
command predates apt
, but is no longer the recommended command for end users.
Users should utilize apt
for package management, as it’s more user-friendly. This is the command meant for everyday use. The apt
command undergoes updates, and its implementation may vary slightly depending on the Linux distribution.
Contrast this to apt-get
, which is less user-friendly, and known to be more consistent over time and across various distros. Scripts, background processes, and system services should utilize apt-get
because of its predictability.
apt-get
, since it was heavily used before the introduction of apt
. Old habits die hard, so some users and websites haven’t made the switch, or they simply don’t understand the difference.