Jump toUpdate content

How to manage packages

Reviewed on 16 July 2021Published on 11 June 2021

Packages are archives containing binaries of pieces of software, along with configuration files and information about dependencies. Often, a package will represent a single application. A package manager is a tool to automate the installation, upgrading and configuration of software on your server, via such packages. It keeps track of all the software packages installed and their various versions, and also helps you remove software that you no longer want.

On Debian and Ubuntu, you should use the APT (Advanced Package Tool) package manager.

Requirements:

How to update repositories

The package system is based on mirrors, generally indicated in /etc/apt/sources.list. When you want to update package information, to get details about updated versions of packages or their dependencies, these sources will be checked. Update your package information with the following command:

sudo apt-get update

The output will vary, but here is one example:

Hit:1 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 https://maven.localazy.com/repository/apt stable InRelease
Hit:3 https://download.docker.com/linux/ubuntu focal InRelease
Hit:4 http://packages.microsoft.com/repos/code stable InRelease
Hit:5 https://dl.yarnpkg.com/debian stable InRelease
Hit:6 http://fr.archive.ubuntu.com/ubuntu focal InRelease
Hit:7 http://fr.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:8 http://ppa.launchpad.net/alex-p/aegisub/ubuntu focal InRelease
Hit:9 http://fr.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:10 https://deb.nodesource.com/node_16.x focal InRelease
Get:11 https://repo.skype.com/deb stable InRelease [4 502 B]
Hit:12 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:13 http://ppa.launchpad.net/peek-developers/stable/ubuntu focal InRelease

How to update packages

Now that your package manager knows the most recent packages available thanks to sudo apt-get update, it can compare that to what is already installed on your server. Use the following command to update your packages to any newer versions that are available:

sudo apt-get upgrade

You may see an output like the following:

Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
apt apt-utils base-files binutils bsdutils cpp-4.8 dh-python gcc-4.8
gcc-4.8-base initscripts iproute2 isc-dhcp-client isc-dhcp-common
libapt-inst1.5 libapt-pkg4.12 libasan0 libasn1-8-heimdal libatomic1
libblkid1 libdrm2 libgcc-4.8-dev libgomp1 libgssapi3-heimdal
libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal
libhx509-5-heimdal libitm1 libkrb5-26-heimdal libmount1 libquadmath0
libroken18-heimdal libstdc++6 libudev1 libuuid1 libwind0-heimdal login mount
passwd python-requests python-six python-urllib3 rsyslog sysv-rc
sysvinit-utils udev util-linux
47 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 21.0 MB of archives.
After this operation, 126 kB of additional disk space will be used.
Do you want to continue? [Y/n]

The package manager asks if you want to upgrade the packages installed on your system, where upgrades are available. To do so, press Y or O, depending on the language of you OS. The upgrade process may take some minutes to complete.

Tip:

You do not always need to reboot after an update, but it is recommended when kernel updates have been made.

How to search for packages

You may want to search for specific software packages. In the example below, we search for the software MariaDB, the OpenSource version of MySQL:

apt-cache search mariadb

This gives the following output:

...
mariadb-client - MariaDB database client (metapackage depending on the latest version)
mariadb-client-5.5 - MariaDB database client binaries
mariadb-client-core-5.5 - MariaDB database core client binaries
mariadb-common - MariaDB common metapackage
mariadb-server - MariaDB database server (metapackage depending on the latest version)
mariadb-server-5.5 - MariaDB database server binaries
mariadb-server-core-5.5 - MariaDB database core server files
mariadb-test - MariaDB database regression test suite (metapackage for the latest version)
mariadb-test-5.5 - MariaDB database regression test suite

We can see that several versions are available. In general it is recommended to choose the “metapackage” when available. Here, we can see that is mariadb-server. The metapackages always install the latest available version, compared to the classic packages (mariadb-server-5.5) which will install version 5.5 and remain on this version.

How to install a package

Use the following command to install a package:

sudo apt-get install PACKAGE

To continue with the MariaDB example, type:

sudo apt-get install mariadb-server

How to keep your system tidy

When you want to install an APT package, it often offers to install others at the same time. This is because of dependencies. A dependency is a small additional piece of software required by your package to function. Over time however, it may be that some dependencies become unused, for example following a chance of dependency for your package.

You can uninstall all unused dependecies with the following command:

sudo apt-get autoremove

How to uninstall a package

If you installed a package just for test purposes, or realized you installed the wrong package, it is easy to remove it. Use the following command:

sudo apt-get remove PACKAGE

If you want to remove all dependencies that were installed with the package at the same time, you can add autoremove:

sudo apt-get autoremove PACKAGE
See Also