Do you want to install a specific version of a package using the apt
or apt-get
command without using modern sandboxing tools like Snap or Flatpak?
Then check your package for all available versions that you want to install by using the below command.
$ apt list --all-versions package_name
Then you can execute the below command for installation of your package, following with the package name, equals symbol, and the version of the package.
$ sudo apt install package_name=package_version
Did your job get done? Or maybe you didn’t find any other versions of your package or you just held a broken package?
Table of Contents
How to Install a Specific Version of a Package on Linux?
Installing a specific version of the package and maintaining the version without being updated on system update is not an easy task. And there are a lot of factors involved in different situations compared to one another.
Read this article thoroughly to learn about them and how to avoid the broken package error while installing an older version of packages.
How to Find Specific or Other Versions of Your Package
There is no straight way to answer this question, but let me tell you. In Linux, whenever you upgrade your package to its newer version, the previous version is automatically removed from the repository and the local database.
However, in some rare situations, like when you hit the apt update
command (but not apt upgrade
), you might find multiple versions of your installed package. One will be your current and the other will be the latest version of that package.
As long as you hit the apt upgrade
command or update your package, it will remove the older version from the repository and local database. When you try to check the available version for your package, you will only find your current version.
You Need to Use Multiple Sources for Different Versions
You heard it right. The default Linux repository will not provide you with the latest (referring to beta or alpha) or outdated version of any package except for the current stable version (or if you issued the apt update
command).
To get the older or latest version of any package, you need to add an external source to your system (for example, PPA). Most of the popular applications provide their own PPA that you can add to your system to get the latest (beta or alpha) release.
For example, I want to install the latest unstable version of the VLC media player, but currently on my system, stable VLC 3.x.x is installed.
To get the latest unstable 4.x.x version of the VLC media player, I need to add the VLC daily build PPA to my system.
Two Sources for Different Versions (Which One Will Have the Highest Priority?)
When you initiate the system update process, there is no doubt that the latest unstable version will have the highest priority (unless you hold the current package from upgrading).
It will remove the older version along with its dependencies and install the latest version with its required dependencies.
Does Upgrading Cause Dependency Issues?
When you install a package, it will also install the required dependencies. Now, there will be many situations where one application’s dependencies also depend on another application.
When you add the PPA and try to install the application to its latest unstable release (referring to VLC 4.x.x), it will install its supporting dependencies by removing the previous dependencies.
If any other package in your system uses the older version of dependencies, it will throw a broken package error. Many times, installing the latest dependencies will solve the issue, unless the program is not stable with the latest dependencies.
That is the reason you should always install the package either by using the Snap, Flatpak, or Appimage. This sandboxing technology wraps the package along with the required dependencies, isolating it from the system.
So, you have to think and take decisions wisely, otherwise, you might end up with a broken system.
Installing a Specific Version of a Package
As I mentioned earlier, I have the latest stable VLC 3.x.x version installed on my system.
$ vlc --version
Below is the output of the above command.
Let’s get all the available versions of VLC.
$ apt list --all-versions vlc
Below is the output of the above command.
As you look above, there is only the latest stable VLC 3.0.16 installed and available on the list. To get all the other versions, you need to add an external source. For example, VLC daily build a PPA.
$ sudo add-apt-repository ppa:videolan/master-daily
Below is the output of the above command.
For demonstration, I am showing you VLC PPA, but you have to add your actual package PPA to get all the other versions.
Now if you re-execute the previous command, you’ll get all the available versions of VLC. You will have multiple versions, as shown below.
$ apt list --all-versions vlc
Below is the output of the above command.
As I’ve mentioned earlier, if you have added multiple sources for the package, it will download and install the latest version of the package.
For example, in the Ubuntu official repository, the latest version of VLC is 3.x.x. However, we have added an external PPA of VLC, which includes the 4.x.x version.
As you know, 4.x.x is the latest version of the VLC media player (even if it is an unstable version). It will be installed when you update your system package and recheck the VLC version.
$ vlc --version
Below is the output of the above command.
Now, in case you want to go back to the older VLC 3.x.x version.
Then you can specify the package name along with the package version during installation, as shown below.
$ sudo apt install vlc=3.0.16-1build7
Below is the output of the above command.
Have you also got the above error? Let me explain what caused this. When you added the latest PPA of VLC and upgraded your system. It installed the latest VLC with the latest dependencies while removing the older version and its dependencies.
But now you are trying to install the older version of VLC, which requires different dependencies. But the latest PPA has the latest dependency information, and as we know, Ubuntu always tries to install the latest version of any package.
Due to which you got this, “You have held broken packages“. So, how can you avoid it? simple by manually installing all the dependencies.
If you look at the error, you’ll find it given all the dependencies and specific versions that it’s complaining about. Just use them to manually install it using the apt install
command, as shown below.
$ sudo apt install vlc=3.0.16-1build7 \
vlc-bin=3.0.16-1build7 \
vlc-plugin-base=3.0.16-1build7 \
vlc-plugin-qt=3.0.16-1build7 \
vlc-plugin-video-output=3.0.16-1build7 \
vlc-l10n=3.0.16-1build7 \
vlc-plugin-access-extra=3.0.16-1build7 \
vlc-plugin-notify=3.0.16-1build7 \
vlc-plugin-samba=3.0.16-1build7 \
vlc-plugin-skins2=3.0.16-1build7 \
vlc-plugin-video-splitter=3.0.16-1build7 \
vlc-plugin-visualization=3.0.16-1build7
Tada! That will do the job for you only in certain conditions.
What Conditions
It will again install the latest version of VLC and its dependencies when you update your whole system.
Then what should I do? There are two ways to prevent it from happening.
- Remove the VLC and PPA from your system and reinstall the VLC from your official repository.
- Hold the VLC version from getting updated to the latest version.
The first method I’ll leave to you; it’s easy to do and up to you. However, if you decide to hold the package from getting updated to its latest version, then you can continue to the next topic. How to hold the package from getting updated.
Holding Package From Auto-Updating
Somehow you get to your specific version of the program or want to prevent your current version of the program from auto-update with your system. Then you can use the apt-mark
command to hold the package from accidentally upgrading to the newer version.
$ sudo apt-mark hold vlc
Replace the “vlc
” with the actual package name.
Now, as many times you try to update your system, it will not update your held package unless you manually update it or unhold it using the following command.
$ sudo apt-mark unhold vlc
Wrap Up
As you can see, it is harder to maintain their dependencies than to install a package. Taking those into mind, you’ve got alternative options like Snap, Flatpak, and Appimage.
If the target version you want to install on your system is available in this sandboxing application, then I recommend you install it from there.
However, it’s up to you. I hope this guide is useful for you and you learned something new. However, if you have any questions left in your mind, then share them with us in the comment section.
Innovative tech mind with 12 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.