Managing Linux Software with APT and dpkg

Managing software on a Linux system can seem daunting to newcomers, but tools like apt
and dpkg make it straightforward and efficient. This tutorial will guide you through
the basics of using apt and dpkg to manage software on Debian-based distributions
like Ubuntu.
What are apt and dpkg?
apt(Advanced Package Tool): A high-level package management system that simplifies the process of installing, updating, and removing software packages. It automatically handles dependencies, ensuring all required software is installed.dpkg(Debian Package): A low-level package manager for Debian-based systems. It handles the installation, configuration, and removal of.debpackages but does not resolve dependencies on its own.
Let’s explore common tasks using apt and dpkg.
Installing a Package with apt
To install a package with apt, use the install command. For example, to install the
text editor vim:
sudo apt update
sudo apt install vim
sudo apt updaterefreshes the list of available packages and their versions.sudo apt install viminstalls thevimpackage.
Uninstalling a Package with apt
To remove a package, use the remove command. For instance, to uninstall vim:
sudo apt remove vim
If you want to remove the package along with its configuration files, use purge:
sudo apt purge vim
Searching for a Package with apt
To search for a package, use the search command. For example, to find packages related
to vim:
apt search vim
This command will list all packages that have vim in their name or description.
Installing Packages from a PPA
Personal Package Archives (PPAs) allow you to install software that is not available in the official repositories. Here’s how to add a PPA and install a package from it. We’ll use the “deadsnakes” PPA, which provides newer versions of Python.
Add the PPA:
sudo add-apt-repository ppa:deadsnakes/ppaUpdate the package list:
sudo apt updateInstall the desired version of Python (e.g., Python 3.9):
sudo apt install python3.9
Installing a Downloaded .deb File with dpkg
Sometimes, you might need to install a package not available in the repositories or
PPAs. You can download a .deb file and install it using dpkg. Here’s how:
Download the
.debfile. For example, let’s download thegoogle-chrome-stablepackage:wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.debInstall the package using
dpkg:sudo dpkg -i google-chrome-stable_current_amd64.debFix any dependency issues:
If
dpkgreports missing dependencies, fix them with:sudo apt install -fThe
-fflag tellsaptto fix broken dependencies.
Conclusion
Managing software on Linux using apt and dpkg is efficient and straightforward once
you understand the basic commands. Here’s a quick recap:
- Use
aptfor high-level package management (install, remove, search). - Add PPAs with
add-apt-repositoryfor additional software sources. - Use
dpkgto handle.debfiles directly, followed byapt install -fto resolve dependencies.
By mastering these tools, you can ensure your system is always up-to-date with the software you need. Happy Linuxing!