Posted on
Administration

Installing specific package versions in DNF

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

How to Install Specific Package Versions in Linux Using DNF, APT, and Zypper

In the world of Linux, managing packages is a fundamental skill for any user, particularly system administrators and developers. Different distributions use different package managers for software installation, updates, dependency checks, and removal. Among these, DNF, APT, and Zypper are widely used by major Linux distributions. Sometimes, installing a specific version of a package is necessary due to compatibility requirements or testing scenarios. Here, we'll guide you on how to install specific package versions using these three package managers.

1. Installing Specific Package Versions with DNF

DNF is the default package manager for Fedora and other RPM-based distributions such as RHEL (Red Hat Enterprise Linux) and its derivatives like CentOS Stream.

To install a specific version of a package with DNF, follow these steps:

Step 1: Search Avilable Versions

Before installation, you might want to check what versions of the package are available. You can do this by:

dnf --showduplicates list <package-name>

This command will list all available versions of the package in the enabled repositories.

Step 2: Install a Specific Version

Once you have identified the version of the package you need, you can install it using:

dnf install <package-name>-<version>

Example:

dnf install nginx-1.18.0

This will install the specified version of Nginx.

Step 3: Setting Package Version Lock (Optional)

If you do not want DNF to upgrade the package during system updates, set a version lock:

dnf install dnf-plugins-core
dnf versionlock add <package-name>-<version>

This will lock the version of the package you installed.

2. Installing Specific Package Versions with APT

APT (Advanced Package Tool) is the staple package management tool for Debian, Ubuntu, and derivatives.

Step 1: Find Available Versions

To look for all versions available in the repository for a particular package:

apt list -a <package-name>

Step 2: Install the Desired Version

To install a specific version, use:

apt install <package-name>=<version>

Example:

apt install nginx=1.18.0

Step 3: Prevent the Package from Upgrading (Optional)

To hold the package at the current version during future updates:

apt-mark hold <package-name>

3. Installing Specific Package Versions with Zypper

Zypper is the command-line interface of ZYpp package manager, which is used by openSUSE and SUSE Linux Enterprise.

Step 1: Search for Package Versions

To find out the versions of a package available to install:

zypper se -s <package-name>

Step 2: Install a Specific Version

To install a specific version:

zypper in <package-name>-<version>

Example:

zypper in nginx-1.18.0

Step 3: Lock the Package Version (Optional)

To prevent the package from being updated:

zypper addlock <package-name>

Conclusion

Understanding how to install specific versions of a package can be invaluable, especially in environments where software compatibility must be strictly managed. Each package manager, be it DNF, APT, or Zypper, offers functionalities that facilitate precise control over package versions, thereby assuring that you have the right tools to maintain system stability and compatibility. Always check the documentation specific to your distribution for the most up-to-date command arguments and options. Happy package managing!