APT (Advanced Package Tool) is the command-line tool to interact with the packaging system. A packaging system is a way to provide programs and applications for installation.
apt actually works on a database of available packages. If the database is not updated, the system won’t know if there are any newer packages available. That is why updating the repository should is the first thing we do in any Linux system's fresh install.
Updating the package database requires superuser privileges in Ubuntu, Ubuntu Mate, and other Debian flavors, so you’ll need to use
sudo apt update
Once you have updated the package database, you can now upgrade the installed packages. The most convenient way is to upgrade all the packages that have available updates. You can simply use the command below:
sudo apt upgrade
This is the faster way to update and upgrade your packages.
sudo apt update && sudo apt upgrade -y
alias uu='sudo apt update && sudo apt upgrade -y'
If you already know the name of the package, you can install it using the command below:
sudo apt install <package_name>
Just replace the with the desired package. Suppose you want to install git, you can simply use the command below:
sudo apt install git
sudo apt install <package_1> <package_2> <package_3>
Removing packages is as easy as installing them. Just use the command below:
sudo apt remove <package_name>
Another way of uninstalling packages is to use
purge. The command is used in the following manner:
sudo apt purge <package_name>
apt removejust removes the binaries of a package. It leaves residue configuration files.
apt purgeremoves everything related to a package including the configuration files.
This command removes libraries and packages that were installed automatically to satisfy the dependencies of an installed package. These are often the previous linux kernels which got updated during the linux update.
sudo apt autoremove
sudo apt --purge autoremove
Let me know in the comments, what are your best APT commands?