Ever needed to install a specific version of a software?
By default, the apt command in Ubuntu installs the latest package version available in the repositories.
If a software's new version has issues, such as bugs, incompatibilities, or removing specific features, it would be better to pick an older version.
Thankfully, Ubuntu offers a simple approach for installing a specific package version with apt.
Installing specific package versions with apt
If you want to install a certain version of a package, just specify it while installing in this fashion.
sudo apt install package_name=package_version
You need the exact version number. You can get the available package versions with:
apt list --all-versions package_name
Let me share a practical example. Let's install Python 3 in Ubuntu 22.04.
But first, let's see all the available versions of Python 3.
sudo apt list --all-versions python3 Listing.. Done python3/jammy-updates,now 3.10.6-1~22.04 amd64 [residual-config] python3/jammy 3.10.4-0ubuntu2 amd64 [residual-config] python3/jammy-updates 3.10.6-1~22.04 i386 python3/jammy 3.10.4-0ubuntu2 i386
As the above output shows, two different versions of Python 3 are available. By default, it will install the newer version 3.10.6. Instead, let's install the older version 3.10.4.
It is important to give the exact package version:
sudo apt install python3=3.10.4-0ubuntu2
Troubleshooting the 'held broken package' issue
Sometimes you get the "Unable to correct problems, you have held broken pages" error while installing a specific package version. This error occurs when the older package version also required installing older versions of its dependencies.
You can try installing the required older versions of all the dependencies like this:
sudo apt install python3=3.10.4-0ubuntu2 \ > python3 minimal=3.10.4-0ubuntu2 \ > libpython3-stdlib=3.10.4-0ubuntu2
However, it may lead to dependency hell if some other package needs a newer version of the same dependency package. Also, dependencies might not have the required older package available in some cases.
Hold the updates on packages
If you have installed the specific version of a package, the system will automatically upgrade it to the latest available version when you update the Ubuntu system the next time.
That's why you must manually lock that software to prevent automatic updates.
In this case, the apt-mark command comes handy as it marks the package as the automatically or manually installed utility:
sudo apt-mark hold <package_name>
We have installed the specific package version of Python 3, so let's hold it from the automatic update:
sudo apt-mark hold python3
You can also unmark the package by only adding unhold in the above command:
sudo apt-mark unhold python3
In the end...
This apt feature helps you in those rare and desperate cases where you must use a specific package version. It may create dependency issues sometimes so please beware of that.
Let me know if you need help or have suggestions.