Install Specific Package Version With Apt Command in Ubuntu - It's FOSS

2022-05-28 10:53:24 By : Ms. Alina Xu

A Linux and Open Source Web Portal

Last updated May 20, 2022 By Abhishek Prakash 9 Comments

Want to install a specific version of a package in Ubuntu? You can do that ‘easily’ in the following manner:

How do you know which versions are available for a certain package? Use this command:

In the screenshot below, you can see that I have two versions of VLC available and I use the command to install the older version:

Sounds like a simple task, right? But things are not as simple as they look. There are several ifs and buts involved here.

This tutorial will cover all the important aspects of installing a specific program version using apt or apt-get commands.

You need to know a few things about how APT and repositories work in Ubuntu and Debian-based distributions.

Ubuntu doesn’t keep older versions of packages in the repository. You may see more than one version in specific cases, temporarily. For example, you run the apt update (but not upgrade), and a new version is available. You may see two versions for the same package in the apt cache. But as soon as the package is upgraded to the new version, the older version is removed from the cache as well as the repositories.

To get multiple versions of the same package, you’ll have to add multiple sources. For example, VLC is in version 3.x. Adding the VLC daily build PPA will give the (unstable) version 4.x.

Similarly, you can download a DEB file with a different version and install it.

If you have the same package available from more than one source, by default, Ubuntu will install the highest available version.

In the previous example, if I install VLC, it will install version 4.x, not 3.x.

That’s another potential problem. Even if you install the older version of a package, it gets upgraded to the newer version (if available). You have to hold the package and stop it from upgrading.

If the package has dependencies, you’ll have to install the required version of the dependent packages as well.

Now that you know a few potential issues let’s see how to tackle them.

I am taking the example of VLC in this tutorial. VLC version 3.0.16 is available in Ubuntu’s repositories. I added the daily build PPA and that gives me the release candidate of VLC version 4.0.

As you can see, I have two VLC versions available in the system right now:

Since the higher version takes priority, using ‘apt install vlc’ will result in the installation of VLC 4.0. But I want to install the older version 3.0.16 for the sake of this tutorial.

But here’s the thing. The vlc package has several dependencies and those dependencies also need specific versions. However, Ubuntu tries to install the available higher versions for them, and thus, you get the classic ‘you have held broken packages‘ error.

To fix this, you have to provide specific versions of all the dependent packages it complains about. So that command becomes something like this:

In case you are wondering, the trailing \ at the end of each line is just a way to write a single command over multiple lines.

Does it work? In many cases, it will. But I have chosen a complicated example of VLC, which has lots of dependencies. Even the mentioned dependencies have dependencies on other packages. It gets messy.

An alternative is to specify the source while installing.

You have added multiple sources, so you should have some idea about the sources the package comes from.

Use the command below and search for the repository:

Focus on the lines that come after the repository name:

You can specify the o,l,a, etc parameters.

In my original example, I want to install VLC from Ubuntu’s repository (to get 3.16) instead of the PPA (which gives me 4).

So the command below will install VLC 3.16 along with all the dependencies:

Looks good? But the problem comes when you have to update the system. Then it complains about not finding the specified version.

What else can be done?

To install an older version, remove the source of the newer version from your system (if possible). It helps get rid of the dependencies hell issues.

If that’s not possible, check if you can get it in some other packaging formats like Snap, Flatpak, AppImage, etc. In fact, Snap and Flatpak also allow you to choose and install from available versions. Since the applications are sandboxed, it’s easier to manage the dependencies for different versions.

If you manage to install a specific program version, you may want to avoid accidentally upgrading to the newer version. It’s not too complicated to achieve this.

You can remove the hold so that it can be upgraded later:

Note that dependencies of a package are not automatically held. They need to be individually mentioned.

As you can see, there is a provision to install the selected version of a program. Things only get complicated if the package has dependencies. Then you get into the dependency hell.

I hope you learned a few new things in this tutorial. If you have questions or suggestions to improve it, please let me know in the comment section.

Like what you read? Please share it with others.

Filed Under: Terminal Tools and Tricks

Creator of It's FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries ranging from Agatha Christie and Sherlock Holmes to Detective Columbo & Ellery Queen. Also a movie buff with a soft corner for film noir.

Thanks for this useful tutorial. However dependency hell seems unavoidable in most of the situations when we try to install a specific version of a package.

Invisibility of windows partition after installing Ubuntu 22.04 has been solved or not? I am waiting for your information. If solved, please announce for the same.

You mean the grub issue? I installed Ubuntu 22.04 with Windows and it worked without issue so I believe it is fixed.

You allude to “apt-get” early in your article. Can “apt-get” be substituted for “apt” in all the command examples above? Small future article suggestion: How to authenticate and verify file downloads such as Debian ISOs or other distro ISO’s or files using GPG keys. Seems the process is often seen as a black art and would be very useful if it was demystified for many while contributing to the integrity and security of the internet. Your articles are clear and concise and appreciated.

I recommend searching for the article here on FOSS titled “Difference Between apt and apt-get Explained.” It gives a detailed comparison of the two commands. Very informative.

Using your example package, VLC, it is a good to point out that trying to circumvent the repos to keep an outdated VLC installed should only be done temporarily to avoid a bug/feature issue until the new version is updated to avoid said bug. That would apply to very few users in most cases. Generally, it is better to accept the version in the repos or as you stated, consider sandboxed versions like flatpak. Alternatively, there may be an upstream version which can be installed, which I prefer to rely on for official Nvidia drivers, VirtualBox, Firefox and Thunderbird. While not difficult, managing your own packages and updates directly from upstream developers is advised only for advanced users.

Agree. I should add this point to the article.

Join 75,000 other Linux users and start your journey to become a better, informed desktop Linux user.

It's FOSS is Part of chmod777 Media Tech (OPC) Pvt Ltd· Built on Genesis Framework and Powered by UpCloud

Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page.