DEV Community

Mohammad Shahbaz Alam
Mohammad Shahbaz Alam

Posted on

5 Must Know APT Commands for a Debian User

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

  1. apt update
  2. apt upgrade
  3. apt install
  4. apt remove
  5. 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
Enter fullscreen mode Exit fullscreen mode

apt update
When you run this command, you’ll see the package information is retrieved from various servers.
apt update output

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
Enter fullscreen mode Exit fullscreen mode

apt upgrade
This will show you how many and which all packages are going to be upgraded.
apt upgrade output

This is the faster way to update and upgrade your packages.

sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

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.
Open .bashrc
Add

alias uu='sudo apt update && sudo apt upgrade -y'
Enter fullscreen mode Exit fullscreen mode

Update .bashrc

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>
Enter fullscreen mode Exit fullscreen mode

Just replace the with the desired package. Suppose you want to install git, you can simply use the command below:

sudo apt install git
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

sudo apt remove vlc

Another way of uninstalling packages is to use purge. The command is used in the following manner:

sudo apt purge <package_name>
Enter fullscreen mode Exit fullscreen mode

sudo apt purge vlc

  • 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
Enter fullscreen mode Exit fullscreen mode

sudo apt autoremove

or try sudo apt --purge autoremove

Let me know in the comments, what are your best APT commands?

Top comments (3)

Collapse
 
oloryn profile image
Ben Coleman

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.

Collapse
 
shahbaz17 profile image
Mohammad Shahbaz Alam

Hmmm,

Nice suggestion.

sudo apt --purge autoremove

Collapse
 
shahbaz17 profile image
Mohammad Shahbaz Alam

pacman😍

Sure, that's helpful.