Use APT Command to Install App with Specific Package Version / Software Source

Have multiple packages for some software, and want to install the specific package version or from the certain software source? Here's how via APT command

Want to install specific version of a package, or package from a certain software source? Here’s how to do the trick in Ubuntu & Debian via APT command.

There’s a few powerful graphical tools such as Synaptic package manager allow to specify which package version to install. However, for those familiar with Linux commands or Ubuntu / Debian Server without GUI, here’s how with APT command.

1. Refresh Package Cache:

After adding / removing software sources or changing the apt preferences, you have to update the system package cache before installing any package. To do so, simply run command:

sudo apt update

Depends on your system and software sources, it outputs something like this:

merilyn@debian11:~$ sudo apt update
[sudo] password for merilyn: 
Hit:1 http://deb.debian.org/debian bullseye-security InRelease                 
Hit:2 http://ftp.us.debian.org/debian bullseye InRelease                                    
Hit:3 http://ftp.us.debian.org/debian bullseye-updates InRelease            
Hit:4 https://deb.opera.com/opera-stable stable InRelease
Reading package lists... Done

2. Install Specific Version of a Package via APT:

Some software have different package versions available in the system, from either same or different sources. Usually, apt will install the package with higher version number. To install an old one, user may either change the package priority, or use the command below:

sudo apt install <package_name>=<version_number>

For instance, the command below will install the phpmyadmin with version “4:4.9.5+dfsg1-2”.

sudo apt install phpmyadmin=4:4.9.5+dfsg1-2
Some app has packages for different CPU architectures. For example, you may try installing 32-bit VLC with version 3.0.9.2-1 on 64-bit machine via command:

sudo apt install vlc:i386=3.0.9.2-1

So, how do you know which versions are available? This command will tell you:

apt list --all-versions <package_name>

As it outputs below, I have two phpmyadmin package versions: “4:5.1.1+dfsg1-3+focal1” and “4:4.9.5+dfsg1-2”.

merilyn@focal:~$ apt list --all-versions phpmyadmin 
Listing... Done
phpmyadmin/focal,focal,now 4:5.1.1+dfsg1-3+focal1 all [installed,local]
phpmyadmin/focal,focal 4:4.9.5+dfsg1-2 all

3. Install Package from Certain Software Source:

It’s possible to specify which software source to install the package from. The command will be:

sudo apt install -t <software_source> <package_name>

Firstly, you need to find out the “<software_source>” to use in command. After running sudo apt update to refresh package cache, check software sources via command:

apt-cache policy |more

This command tells all the software sources in system. Here I’m going to check the Phpmyadmin PPA, and the line below define the source in the picture:

“release v=20.04,o=LP-PPA-phpmyadmin,a=focal,n=focal,l=PPA for phpMyAdmin,c=main,b=amd64″

To be unique, I can use either “o=LP-PPA-phpmyadmin” or “l=PPA for phpMyAdmin” to specify the PPA source in apt command. So, to install phpmyadmin from the PPA using command:

sudo apt install -t "o=LP-PPA-phpmyadmin" phpmyadmin

Or:

sudo apt install -t "l=PPA for phpMyAdmin" phpmyadmin

That’s all. Enjoy!

Exit mobile version