Linux Commands

How to Use “Apt Install” to Install a Specific Version of a Package in Linux

By default, the “apt” command installs the latest version of the package. But, sometimes, it shows an error, bugs, incompatibilities, etc. To avoid these problems, you can install any other or older version of that package. That’s why it offers a simple approach to installing the specific version of any package.

However, many Linux users do not know about the secret feature of the “apt” utility. So, in this short guide, we will explain the simplest way to use “apt install” to install a specific version of a package in Linux.

How to Use “Apt Install” to Install a Specific Version of a Package in Linux

First, list all the available versions of a package using the following “apt” command:

apt list --all-versions <package_name>

For example, we install a “testdisk” package here, and you can see that there’s only one version available.

The general syntax to install a specific version of any package is as follows:

sudo apt install <package_name>=<package_version>

Now, we install the “testdisk” package of the previous version using the following command:

sudo apt install testdisk=7.1-5build1

Here, the “testdisk” of version 7.1 is successfully installed. You can also verify it using the following command:

testdisk --v

Protect the Installed Version from Updates

Installing any specific tool version is simple, but you must lock it from the updates. So, all you have to do is run the following command to mark it as the manually installed utility:

sudo apt-mark hold testdisk

In case you want to update the package, you need to unhold it by running the following command:

sudo apt-mark unhold testdisk

Conclusion

The “apt” command of Linux offers a simple option to install a specific version of the package. Sometimes, there are some dependencies issues where you have to install the dependencies manually. From the provided method, you can easily install the specific version of the package and accomplish the task using that particular package.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.