Mastering these basic apt commands will elevate your CLI skills
As you may know, APT (Advanced Package Tool) is a command-line utility for managing packages on Ubuntu, Debian and derivative systems. Among others, it’s the tool you use to upgrade the system, add a repository, check if a package is available in a repo or install a package.
For Ubuntu and derivative systems, also dpkg and snap package managers are available, but in this article I will only cover APT.
1. APT Commands For Beginners: Update the Package List
sudo apt update
Technically speaking, this command does not update any package on the system. It only checks all the available repositories and updates the list. If there is a new version of Chromium available, after you run apt update, you will be able to install the new version on your system with apt install.
It’s crucial to understand its role in maintaining system security and stability. Regularly running apt update
ensures that your system is aware of the latest security patches and software versions.
This practice is especially important before installing new software, as it guarantees that you’re accessing the most recent and secure versions available in the repositories.

2. APT Commands for Beginners: Upgrade Installed Packages
sudo apt update
sudo apt upgrade
The apt update command updates the repository files and discovers the available software updates, while the apt upgrade commands upgrade does the actual upgrade of the packages.
Beyond the basic functionality of upgrading installed packages, the apt upgrade
command plays a pivotal role in system maintenance.
By consistently applying available updates, users can benefit from improved features, bug fixes, and enhanced security measures. It’s advisable to run this command periodically to ensure that all applications and system components function optimally and securely.

3. APT Commands for Beginners: Install a Package
sudo apt update
sudo apt install <package-name>
It is a common practice to update the repository index with apt update, before installing anything new with apt install.
The apt install command installs the latest version of the package found inside the added repositories.
For example, to install GIMP, you can do sudo apt install gimp.
Installing software using apt install
is straightforward, but understanding the underlying process can be enlightening.
When you execute this command, APT resolves all necessary dependencies, ensuring that the software functions correctly. For instance, installing a complex application like GIMP requires several libraries and tools; APT manages this seamlessly, providing a hassle-free installation experience.
4. Mastering Apt: Remove a Package
sudo apt remove <package-name>
This removes a package, but keeps the current configuration files.
For example, sudo apt remove gimp removes GIMP.

The apt remove
command is useful for uninstalling software while preserving configuration files. This approach is beneficial if you anticipate reinstalling the software in the future, as your previous settings will be retained.
However, if you aim to completely eliminate the software and its configurations, the apt purge
command is more appropriate.
5. APT Commands For Beginners: Purge a Package (Remove Configuration Files)
sudo apt purge <package-name>
This removes both the package and the configuration files. For example sudo apt purge gimp removes GIMP and all the customizations and saved configs.
This can also be used ever of gimp has been already removed with apt remove, deleting only the configuration files, if the software is not installed.

Using apt purge
ensures a thorough removal of both the software and its associated configuration files. This is particularly useful when you want to reset an application to its default settings upon reinstallation or when you need to free up system resources by eliminating unnecessary files.
6. Mastering APT: Search for a Package
apt search <package-name>
This command looks inside the available repositories and shows if any package with or containing that name is available. No sudo is needed here, as this does not change any system file.
For example, apt search mixxx shows the Mixxx version which is available via the already existent repositories.

The apt search
command is a powerful tool for exploring available software. By providing keywords or partial names, you can discover a range of applications that suit your needs. This command searches through package names and descriptions, offering a comprehensive list of potential matches.
7. APT Commands For Beginners: Show Package Information
sudo apt update
apt show <package-name>
It is common practice to refresh the repository index before using apt show, so that you see the information about the latest version of the package available. This is what apt show mixxx command outputs:

Delving into a package’s details with apt show
provides valuable insights, such as the software’s purpose, version, dependencies, and maintainer information. This information is crucial when assessing the suitability of software for your system or when troubleshooting dependency issues.
8. APT Commands For Beginners: List Upgradable Packages
sudo apt update
apt list --upgradable
This lists all the packages that have updates available.

Before performing a system upgrade, it’s beneficial to know which packages have available updates. The apt list --upgradable
command offers a clear overview, allowing you to prioritize critical updates or postpone non-essential ones based on your requirements.
9. APT Commands For Beginners: Clean Up Unused Packages
sudo apt autoremove
The sudo apt remove commands uninstalls all the packages that are not used anymore, because they were installed as dependencies for other packages.

Over time, your system may accumulate unnecessary packages, especially after uninstalling software. The apt autoremove
command helps maintain a lean system by identifying and removing these redundant packages, thereby freeing up disk space and reducing potential security vulnerabilities.
10. APT Commands For Beginners: Fix Broken Install
sudo apt --fix-broken install
This command resolves and installs any missing or broken dependencies. Also, it offers to remove the dependencies which are not used anymore, similar to sudo apt autoremove.

Encountering broken dependencies can disrupt the functionality of your system. The apt --fix-broken install
command is a remedial tool that attempts to resolve these issues by installing missing dependencies or removing conflicting packages, ensuring system integrity.
By understanding and effectively utilizing these APT commands, beginners can confidently manage software packages, ensuring their systems remain up-to-date, secure, and tailored to their needs.