Package Management

In the daily use and system administration of Linux operating systems, managing software packages is critically important. Linux distributions provide various package managers to facilitate tasks such as software installation, updating, and removal. These package managers allow you to manage software in package formats, along with their dependencies.

Each Linux distribution uses specific package management systems and package formats. In this section, we will explore package management tools commonly used in Debian-based Linux distributions and their basic usages.

Key Features of Package Managers

Linux package managers offer various features for managing software packages:

  • Package Downloading: Automatically download software packages and dependencies from the internet.

  • Dependency Resolution: Identify and automatically install the dependencies required by a package.

  • Package Installation and Removal: Install software packages to the system and remove them when necessary.

  • Updates and Upgrades: Check for new versions of installed packages and update them.

  • Configuration Files and Directories: Provide standards for the configuration files and directories of software packages.

Advanced Package Manager (APT)

APT (Advanced Package Tool) is a powerful tool used to manage software packages in Debian-based Linux distributions such as Ubuntu. This tool allows users to easily install new software, update existing software, remove unnecessary ones, and automatically resolve dependencies between software packages. With simple command-line commands, users can keep their systems up-to-date and secure, while also quickly accessing the software they need. The convenience and efficiency offered by APT make it a popular choice among Linux users.

Updating Package Lists

APT keeps package lists in a database on your local system. It doesn't connect to servers each time you search, thus providing faster results, but the results might not be up-to-date. To get the most current results, you need to update your lists.

To update your package list with apt, use the update command.

user@hackerbox:~$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... 
DoneAll packages are up to date.

Searching in Package Lists

Now that we have updated the package lists in the database, we can search within those lists. For example, to search for a package with the name htop, you can perform the following search.

As you can see in the results, in addition to the htop package, there are other unrelated packages. This is because the apt search command also searches within the package descriptions. For example, if we look at the description of the aha package, we can see where htop is mentioned.

The apt search command supports regular expressions. For example, to search for packages starting with htop, you could do:

Or, you could search for packages whose names contain the term htop.

Installing and Updating Packages

To install a package found, use the apt command.

This command also updates an existing installed package to the latest version if it's already installed.

To update all packages on your system, you can use the upgrade command.

This method will not install any new packages or remove any old ones. If this isn't a concern, you can use the dist-upgrade command.

Removing Packages

To remove a package, use the remove command.

The output above shows that the htop package has been successfully removed from the system, freeing up 201 kB of disk space.

The remove command does not delete the configuration files and deb files for htop. To remove those as well, you would use the purge command.

Last updated