1. Overview

DNF is a package manager commonly used to install packages on Linux distributions like Fedora, CentOS, and RedHat Enterprise Linux (RHEL). Apart from just installation, the DNF package manager lets us manage and delete various software packages.

In this tutorial, we’ll explore the dnf command to install a specific version of a Linux package.

2. Install a Package

Before installing any package on a Linux system, we must update the package metadata repository. To illustrate, let’s look at the command:

$ sudo dnf update

The above command fetches the package information from remote servers. The dnf update command checks for package updates and downloads any new package versions. It doesn’t install any new packages but updates all existing packages. Furthermore, it resolves package dependencies so that they are compatible with each other. Sometimes, we may need root access to install certain packages.

2.1. Check the Installed Version

Before moving forward, we first need to check the installed version. To demonstrate, let’s look at the command:

$ sudo dnf list installed python3 
Installed Packages
python3.aarch64                                                                                  3.11.5-1.fc38                                                                                    @updates

In the above output, we can see that python3.aarch64 is already installed on this machine.

2.2. Check the Available Version

To install a particular package, it is essential to know whether that package is available or not. To illustrate, let’s look at the command:

$ sudo dnf list python3 --showduplicates
Last metadata expiration check: 0:00:03 ago on Tue Sep 12 03:24:32 2023.
Installed Packages
python3.aarch64                                                                                    3.11.5-1.fc38                                                                                    @updates
Available Packages
python3.aarch64                                                                                    3.11.2-1.fc38                                                                                    fedora  
python3.aarch64                                                                                    3.11.5-1.fc38                                                                                    updates

The above command simply lists all the available versions of the python3 package. Furthermore, we can see that python3-3.11.2-1.fc38.aarch64 and python3-3.11.5-1.fc38.aarch64 are available for installation.

2.3. Uninstall the Current Version

To install a new version of the package, we always have to uninstall the previous version of that package. To demonstrate, let’s look at the command to uninstall a package using the DNF package manager:

$ sudo dnf remove python3

The above command removes the python3 package. The dnf remove command will remove all the associated files and configurations from the system related to that package. This will prompt us to confirm the removal of the package since it can’t be recovered.

2.4. Install a Specific Package Version

So far, we have looked at commands to list and remove a package using the DNF package manager. Now, let’s look at commands to install a specific version:

$ sudo dnf install -y python3-3.11.2-1.fc38.aarch64

The DNF will resolve all the dependencies and install the python3-3.11.2-1.fc38.aarch64 version.

2.5. Verification of Installation

On successfully installing the DNF package, we can also verify the correct version of a package:

$ rpm -q python3-3.11.2-1.fc38.aarch64
python3-3.11.2-1.fc38.aarch64

The above command will display the installed version of the package. Also, we can verify it using the python3 command:

$ python3  --version
Python 3.11.2

The above output shows the 3.11.2 version of the python3 package is installed successfully.

3. Conclusion

In this article, we explored the dnf install command to install a specific version of a Linux package. Afterward, we checked the installed version and the available version, uninstalled the current version, and installed the specific package version.

Furthermore, we also looked at the commands to verify the exact installed package version.

Comments are closed on this article!