What is apt?
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.
Must Know APT Commands
apt update
apt upgrade
apt install
apt remove
apt autoremove
apt update
Update package database with apt
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
.
sudo apt update
When you run this command, you’ll see the package information is retrieved from various servers.
apt upgrade
Upgrade installed packages with apt
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 will show you how many and which all packages are going to be upgraded.
This is the faster way to update and upgrade your packages.
sudo apt update && sudo apt upgrade -y
Or set an alias, uu
for the above command. Here's how you can set up an alias in Linux.
Add
alias uu='sudo apt update && sudo apt upgrade -y'
apt install
Install new packages with apt
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
You can install several packages at a time by providing the package names all together:
sudo apt install <package_1> <package_2> <package_3>
apt remove
Remove installed packages with apt
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 remove
just removes the binaries of a package. It leaves residue configuration files. -
apt purge
removes everything related to a package including the configuration files.
apt autoremove
Clean your system with apt
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
or try sudo apt --purge autoremove
Let me know in the comments, what are your best APT commands?
Top comments (3)
And when I do autoremove, I normally do
sudo apt --purge autoremove
so any configuration files for the packages it removes are also removed. Of course, this is done often enough that it ought to be put into a script or an alias.
Hmmm,
Nice suggestion.
sudo apt --purge autoremove
pacman😍
Sure, that's helpful.