Install Specific Version with APT Package Manager


Ubuntu

Author: Omer Cakmak
Reviewer: Deepak Prasad

You can follow the below provided steps to install a specific version of package using APT package manager on Debian-based Linux distributions (like Ubuntu):

 

Step 1: Update the Package List

Before you install or update any package, it is always a good practice to update the package list of your machine. This will ensure that your machine has the latest information about available packages and their versions inside repositories.

You will need either sudo access or you can run the following apt command as root user:

sudo apt update

 

Step 2. Find Available Versions of the Package

You can use apt-cache madison command to check and list the available versions for the provided package in the repository:

apt-cache madison <package-name>

For example, to find available versions of python3, you would use:

apt-cache madison python3

Sample Output:

   python3 | 3.10.6-1~22.04 | http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
python3 | 3.10.6-1~22.04 | http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages
python3 | 3.10.4-0ubuntu2 | http://in.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
Install Specific Version with APT Package Manager

 

Step 3: Decide to Install or Update

If the package is not installed and you want to install a specific version then you can use:

sudo apt install <package-name>=<version>

If the package is installed but an update is available then you can use:

sudo apt install --only-upgrade <package-name>

Let's check in my case if python3 is already installed or not using dpkg command:

$ dpkg -l python3

Sample Output:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-==============-============-=========================================================================
ii python3 3.10.6-1~22.04 amd64 interactive high-level object-oriented language (default python3 version)

So in my case latest version of python3 is already installed. But for the sake of this tutorial I will go ahead and try to install an older version from the available list i.e. 3.10.6-1~22.04

sudo apt install  python3=3.10.4-0ubuntu2 -y
Install Specific Version with APT Package Manager

But unfortunately the installation failed to unmet dependencies.

 

Step 4: Handling dependency conflicts (Optional)

If the last step was successful for you without any dependency conflicts then you can skip this step. In my case since I was trying to install old version of python3 package so it is expecting some more dependencies for that specific version.

The error basically means that when trying to install a specific version of Python 3 (python3=3.10.4-0ubuntu2) on my Ubuntu system expects dependencies of the package (python3-minimal and libpython3-stdlib) which are expected to be of the same version as the package we are trying to install. However, the versions available or to be installed for these dependencies are newer (3.10.6-1~22.04). This mismatch leads to a conflict that apt cannot resolve automatically.

To resolve this, I will need to install the exact versions of the dependencies that are compatible with python3=3.10.4-0ubuntu2. So let's try the same:

sudo apt install python3=3.10.4-0ubuntu2 python3-minimal=3.10.4-0ubuntu2 libpython3-stdlib=3.10.4-0ubuntu2 -y

But unfortunately I get some more dependency conflicts:

Install Specific Version with APT Package Manager

So this solution isn't working for me.

In such cases it is recommended to use aptitude for a more interactive resolution process:

sudo apt install aptitude

Ensure that you have all the appropriate repositories enabled, especially the "universe" and "main" repositories where different Python versions might reside:

sudo add-apt-repository universe
sudo apt update

Next go ahead and attempt to install python using aptitude with your specific version:

sudo aptitude install python3=3.10.4-0ubuntu2

This command will suggest multiple solution such as downgrading certain packages or even uninstalling conflicting packages.

The following NEW packages will be installed:
python3{b} python3.10{a} python3.10-minimal{a}
0 packages upgraded, 3 newly installed, 0 to remove and 27 not upgraded.
Need to get 22.8 kB/2,773 kB of archives. After unpacking 6,780 kB will be used.
The following packages have unmet dependencies:
python3 : PreDepends: python3-minimal (= 3.10.4-0ubuntu2) but it is not going to be installed
Depends: libpython3-stdlib (= 3.10.4-0ubuntu2) but it is not going to be installed
The following actions will resolve these dependencies:

Keep the following packages at their current version:
1) python3 [Not Installed]



Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

Install the following packages:
1) libpython3-stdlib [3.10.4-0ubuntu2 (jammy)]
2) python3-minimal [3.10.4-0ubuntu2 (jammy)]



Accept this solution? [Y/n/q/?] Y
The following NEW packages will be installed:
libpython3-stdlib{a} python3 python3-minimal{a} python3.10{a} python3.10-minimal{a}
0 packages upgraded, 5 newly installed, 0 to remove and 27 not upgraded.
Need to get 54.2 kB/2,805 kB of archives. After unpacking 6,945 kB will be used.
Do you want to continue? [Y/n/?] Y
Get: 1 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 python3-minimal amd64 3.10.4-0ubuntu2 [24.4 kB]
Get: 2 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 libpython3-stdlib amd64 3.10.4-0ubuntu2 [6,990 B]
Get: 3 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 python3 amd64 3.10.4-0ubuntu2 [22.8 kB]
Fetched 54.2 kB in 1s (49.2 kB/s)
Selecting previously unselected package python3.10-minimal.
(Reading database ... 246497 files and directories currently installed.)
Preparing to unpack .../python3.10-minimal_3.10.12-1~22.04.3_amd64.deb ...
Unpacking python3.10-minimal (3.10.12-1~22.04.3) ...
Setting up python3.10-minimal (3.10.12-1~22.04.3) ...
(Reading database ... 246507 files and directories currently installed.)
Preparing to unpack .../python3-minimal_3.10.4-0ubuntu2_amd64.deb ...
Unpacking python3-minimal (3.10.4-0ubuntu2) ...
Preparing to unpack .../python3.10_3.10.12-1~22.04.3_amd64.deb ...
Unpacking python3.10 (3.10.12-1~22.04.3) ...
Preparing to unpack .../libpython3-stdlib_3.10.4-0ubuntu2_amd64.deb ...
Unpacking libpython3-stdlib:amd64 (3.10.4-0ubuntu2) ...
Setting up python3-minimal (3.10.4-0ubuntu2) ...
Selecting previously unselected package python3.
(Reading database ... 246552 files and directories currently installed.)
Preparing to unpack .../python3_3.10.4-0ubuntu2_amd64.deb ...
Unpacking python3 (3.10.4-0ubuntu2) ...
Setting up python3.10 (3.10.12-1~22.04.3) ...
Setting up libpython3-stdlib:amd64 (3.10.4-0ubuntu2) ...
Setting up python3 (3.10.4-0ubuntu2) ...
running python rtupdate hooks for python3.10...
running python post-rtupdate hooks for python3.10...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
W: APT had planned for dpkg to do more than it reported back (12 vs 21).
Affected packages: python3.10-minimal:amd64 python3:amd64

Current status: 30 (+3) upgradable.

As you can see, the aptitude command has given us the best possible solution to handle all dependency and still be able to install the specific version of python3 package.

 

Step 5: Verify Installation

Once the previous steps have completed successfully, use dpkg command to check the currently installed version of the package you were installing, in our case Python3

dpkg -l python3

Output:

Install Specific Version with APT Package Manager

So we have successfully installed Python with specific version using aptitude. Now in your case if you don't have any dependency conflicts then you just use apt command as per the syntax I have shared in previous steps.

 

Views: 253
Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment