Posted on
Administration

Installing specific package versions in APT

Author
  • User
    Linux Bash
    Posts by this author
    Posts by this author

How to Install Specific Package Versions in Linux: A Guide for APT, DNF, and Zypper

When setting up or maintaining a stable environment on your Linux system, sometimes you need to install a specific version of a package. This could be due to compatibility issues, testing requirements, or rollback scenarios after an update didn’t go as expected. While the process can vary slightly depending on the package manager you are using — whether it's APT (used by Debian and Ubuntu), DNF (used by Fedora), or Zypper (used by openSUSE) — the fundamental approach remains similar. Let's explore how to handle this task in each package manager.

1. Using APT to Install Specific Package Versions

APT (Advanced Package Tool) is the default package manager for Debian-based distributions like Ubuntu. Here’s how you can install a specific version of a package using APT:

Step 1: Update APT index First, you need to update your package list to make sure you have the latest information on available packages:

sudo apt update

Step 2: Find available versions Before you can install, it's helpful to know which versions of the package are available for installation:

apt list -a package_name

Replace package_name with the name of the package whose versions you want to review.

Step 3: Install a specific version Once you've identified the version you need, you can install it using:

sudo apt install package_name=version

Replace package_name with the name of your package and version with the specific version number.

2. Using DNF for Specific Package Installations

DNF is the next-generation version of YUM and is used by Fedora and other RPM-based distributions. Here’s how to install a specific version of a package using DNF:

Step 1: List available versions To see what versions of the package are available, use:

dnf --showduplicates list package_name

This command shows all available versions of the package in the repositories.

Step 2: Install the desired version To install a specific version, use the following command:

sudo dnf install package_name-version

Ensure you replace package_name with your desired package and version with the full version string (including the release number if applicable).

3. Using Zypper to Install Specific Versions

Zypper is the command line interface of ZYpp package manager for installing, updating and removing packages as well as for managing repositories. It is used by openSUSE and SLE based systems.

Step 1: Query available versions First, check the versions of the package available with:

zypper se -s package_name

This search will list all available versions of the package in your configured repositories.

Step 2: Install a specific version To install a particular version, use the command:

sudo zypper in package_name=version

package_name is your target package and version is the specific version number you wish to install.

Conclusion

Having the ability to install specific package versions is a valuable skill for any Linux system administrator. This can help in maintaining consistency across development, testing, and production environments or when troubleshooting issues related to specific updates.

While different package managers might have slightly different commands, the underlying principle remains the same: query available versions and specify the desired version during installation. Whether you're using APT, DNF, or Zypper, the steps outlined should guide you through managing the versions of packages effectively.