Managing Packages in Ubuntu

Overview

In this tutorial, you will be shown advanced package management for Ubuntu Server, including how to downgrade packages and holding a package at a specific version.

While most day-to-day operations of an Ubuntu server usually include full system updates or installing the latest packages, there are times where we may need a specific version of package. You may also find yourself in a scenario where a package must be downgraded to address a bug introduced in an upgrade.

Installing a Specific Package Version

While most package installations target the most recently released updates, there are times where we need to install specific version for satisfying other requirements. It could that third-party vendor solution requires has only been qualified for a version two releases below the most recent one.

There are two methods for installing a specific package version. One is to provide the entire package name, including version number, with the apt-get install command.

sudo apt install <package-name>=<package-version-number>

The second method is to use the -t flag with apt install to target a specific release version.

sudo apt -t=<target release> install <package-name>

Downgrading an Installed Package

To downgrade an installed package we simply install a previous version available from the package’s source repo. We use the same commands used above to install a specific version.

Apt will remove the currently installed version and replace it with the version we specify.

sudo apt -t=<target release> install <package-name>

Listing All Available Package Version

While it is useful to understand how to install a specific package version, you will be limited to the version available from the source package repo. The apt-cache command can be used to list all available version of a package.

apt-cache showpkg <package-name>

Prevent a Package from Updating

On occasion, you could be required to always run a specific version of a package. In order to prevent a package from being upgraded a hold can be placed on the currently installed version. The hold will prevent a package from being updated whenever the entire system is updated using apt upgrade.

To place a hold on a package version, the apt-mark command is used.

apt-mark hold <package-name>