Package Management in Debian-based Distributions

Posted: | Last updated: | 5 minute read

Inception: Learn about Package Management in Debian GNU/Linux based distributions. Package management refer to the ability to install packages in the system. It’s a way to install applications in your Linux system. In this article you will learn how to install, remove, or upgrade packages/libraries/application in Debian based distributions.

In this article you are going to run many commands to manage the packages.

Almost every Linux distribution has a concept of the repository, which helps in installing, removing, and updating applications in the system. A repository is an online server that contains one or more packages.

Most of the time, based on your distribution type you will have the main repository, and everything comes from that repository.

In Debian you will be using apt series of commands. The apt is supported in Debian and Ubuntu based distributions.

Package Management in Debian-based Distributions

First, you need to make sure that your package index locally is synchronized with the server externally. Use the following command to update the package index.

vagrant@debian10:~$ sudo apt update
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Hit:2 http://deb.debian.org/debian buster InRelease
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main Sources [132 kB]
Get:5 http://security.debian.org/debian-security buster/updates/main amd64 Packages [217 kB]
Get:6 http://security.debian.org/debian-security buster/updates/main Translation-en [118 kB]
Fetched 584 kB in 1s (444 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
vagrant@debian10:~$

The above command will not update the packages but simply update the repository. It will connect with all the repositories you have configured and update the package lists locally.

It will also show, how many packages can be upgraded.

Important apt commands in Debian distro:

List upgradeable packages in Debian distro

vagrant@debian10:~$ apt list --upgradable
Listing... Done
grub-common/stable 2.02+dfsg1-20+deb10u2 amd64 [upgradable from: 2.02+dfsg1-20+deb10u1]
grub-pc-bin/stable 2.02+dfsg1-20+deb10u2 amd64 [upgradable from: 2.02+dfsg1-20+deb10u1]
grub-pc/stable 2.02+dfsg1-20+deb10u2 amd64 [upgradable from: 2.02+dfsg1-20+deb10u1]
grub2-common/stable 2.02+dfsg1-20+deb10u2 amd64 [upgradable from: 2.02+dfsg1-20+deb10u1]
vagrant@debian10:~$

Search packages

Following are the command to search firefox package.

vagrant@debian10:~$ apt search firefox
Sorting... Done
Full Text Search... Done
amule-gnome-support/stable 1:2.3.2-5 all
  ed2k links handling support for GNOME web browsers

bleachbit/stable 2.0-3 all
  delete unnecessary files from the system

buku/stable 4.1+ds-2 all
  Powerful command-line bookmark manager

cbindgen/stable 0.8.7-1 amd64
  Generates C bindings from Rust code

chrome-gnome-shell/stable 10.1-5 all
  GNOME Shell extensions integration for web browsers

firefox-esr/stable 68.11.0esr-1~deb10u1 amd64
  Mozilla Firefox web browser - Extended Support Release (ESR)

firefox-esr-l10n-ach/stable 68.11.0esr-1~deb10u1 all
  Acoli language package for Firefox ESR
.
.
.
vagrant@debian10:~$

Install package

Run sudo apt install PACKAGE_NAME to install the package.

vagrant@debian10:~$ sudo apt install vim-nox
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  fonts-lato javascript-common libjs-jquery liblua5.2-0 libruby2.5 libtcl8.6 libyaml-0-2 rake ruby ruby-did-you-mean ruby-minitest ruby-net-telnet ruby-power-assert
Preparing to unpack .../16-libtcl8.6_8.6.9+dfsg-2_amd64.deb ...
Unpacking libtcl8.6:amd64 (8.6.9+dfsg-2) ...
Selecting previously unselected package unzip.
Preparing to unpack .../17-unzip_6.0-23+deb10u1_amd64.deb ...
Unpacking unzip (6.0-23+deb10u1) ...
Selecting previously unselected package vim-nox.
Preparing to unpack .../18-vim-nox_2%3a8.1.0875-5_amd64.deb ...
Unpacking vim-nox (2:8.1.0875-5) ...
.
.
.
update-alternatives: using /usr/bin/vim.nox to provide /usr/bin/ex (ex) in auto mode
Processing triggers for mime-support (3.62) ...
Processing triggers for libc-bin (2.28-10) ...
Processing triggers for man-db (2.8.5-2) ...

vagrant@debian10:~$ which vim
/usr/bin/vim

Install apache2 webserver

While installing apache2 web server, you will notice that it will show you number of upgraded, newly installed, to remove, and additional disk space will be used. Check the list carefully before you hit the Y and press enter.

vagrant@debian10:~$ sudo apt install apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libjansson4
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libjansson4
0 upgraded, 10 newly installed, 0 to remove and 4 not upgraded.
Need to get 2496 kB of archives.
After this operation, 8450 kB of additional disk space will be used.
Do you want to continue? [Y/n]
.
.
.
Processing triggers for systemd (241-7~deb10u4) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10) ...
vagrant@debian10:~$

Remove apache2 webserver

If you have installed a package through apt, then you can install it by using below command.

vagrant@debian10:~$ sudo apt remove apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libjansson4
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  apache2
0 upgraded, 0 newly installed, 1 to remove and 4 not upgraded.
After this operation, 613 kB disk space will be freed.
Do you want to continue? [Y/n]
.
.
.
(Reading database ... 63277 files and directories currently installed.)
Removing apache2 (2.4.38-3+deb10u3) ...
Processing triggers for man-db (2.8.5-2) ...
vagrant@debian10:~$

Cleanup unwanted packages

While installing, apt might have installed additional packages. But when you removed the packages then few of the dependency packages might not have uninstalled/removed.

So that to remove them, you can use the below command.

vagrant@debian10:~$ sudo apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libbrotli1 libjansson4
0 upgraded, 0 newly installed, 9 to remove, and 4 not upgraded.
After this operation, 7837 kB disk space will be freed.
Do you want to continue? [Y/n]
.
.
.
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10) ...
vagrant@debian10:~$

Upgrade the installed packages

In case of any new version upgrade, you can simply update the package manager and after that, you can run the below command to upgrade the packages.

vagrant@debian10:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove, and 0 not upgraded.
vagrant@debian10:~$
vagrant@debian10:~$
vagrant@debian10:~$ sudo apt dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove, and 0 not upgraded.
vagrant@debian10:~$
Conclusion: Now you can install, remove, and upgrade packages/applications in Debian based distributions. You learned apt package manager in Debian system.