How to Install a Specific Version with APT

Learn how to install a specific package version with apt or apt-get on Ubuntu and Debian, list available versions, simulate installs safely, handle dependency conflicts, and hold or unhold package versions.

Published

Updated

Read time 8 min read

Reviewed byDeepak Prasad

How to Install a Specific Version with APT

APT can install an exact package version when that version is available from your enabled repositories. The syntax is simple, but the safe workflow matters: first list available versions, then simulate the install, then install the exact version only after you understand any upgrades, downgrades, removals, or dependency changes.

This guide shows how to install a specific package version on Ubuntu and Debian-based systems using apt and apt-get. The tested examples use vim-tiny because this host has more than one available version in the configured repositories.

IMPORTANT
Do not blindly downgrade core packages such as python3, libc6, systemd, openssl, or kernel packages on a production system. Always simulate first and review dependencies.

Quick Command Summary

Task Command
Update package metadata sudo apt update
Show installed, candidate, and available versions apt-cache policy package
Compact version list apt-cache madison package
List versions with apt apt list -a package
Check installed version dpkg-query -W package
Simulate exact version install apt-get install --simulate package=version
Install exact version sudo apt install package=version
Install exact version with apt-get sudo apt-get install package=version
Hold a package sudo apt-mark hold package
Remove hold sudo apt-mark unhold package

Quick Syntax

Install a specific package version interactively:

bash
sudo apt install package=version

Use the stable apt-get interface for scripts or automation:

bash
sudo apt-get install package=version

Preview the exact-version install without changing the system:

bash
apt-get install --simulate package=version

For more APT basics, see the apt command examples and apt-cache command examples. If you are installing a local package file instead of a repository version, see how to install .deb files in Linux.


1. Update the Package List

Update package metadata before checking available versions. This makes sure APT is using the latest package lists from enabled repositories.

bash
sudo apt update

Tested output:

text
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Hit:1 http://archive.ubuntu.com/ubuntu plucky InRelease
Hit:2 http://archive.ubuntu.com/ubuntu plucky-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu plucky-backports InRelease
Hit:4 https://download.docker.com/linux/ubuntu plucky InRelease
Hit:5 http://security.ubuntu.com/ubuntu plucky-security InRelease
Reading package lists...
Building dependency tree...
Reading state information...
51 packages can be upgraded. Run 'apt list --upgradable' to see them.

The warning is normal for apt. It means apt is intended for interactive use. For scripts, prefer apt-get.

You need root or sudo access for apt update; see how to add a user to sudo group if your account cannot run sudo.


2. Find Available Versions with apt-cache policy

Use apt-cache policy package to see the installed version, candidate version, and versions available from enabled repositories.

bash
apt-cache policy vim-tiny

Tested output:

text
vim-tiny:
  Installed: 2:9.1.0967-1ubuntu4.1
  Candidate: 2:9.1.0967-1ubuntu4.1
  Version table:
 *** 2:9.1.0967-1ubuntu4.1 500
        500 http://archive.ubuntu.com/ubuntu plucky-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu plucky-security/main amd64 Packages
        100 /var/lib/dpkg/status
     2:9.1.0967-1ubuntu4 500
        500 http://archive.ubuntu.com/ubuntu plucky/main amd64 Packages

In this output:

  • Installed is the version currently installed.
  • Candidate is the version APT would normally install or upgrade to.
  • The version table shows other available versions and their repositories.
  • 2:9.1.0967-1ubuntu4.1 includes an epoch (2:), so the full version string must be used when installing an exact version.

3. Find Available Versions with apt-cache madison

apt-cache madison gives a compact version list.

bash
apt-cache madison vim-tiny

Tested output:

text
vim-tiny | 2:9.1.0967-1ubuntu4.1 | http://archive.ubuntu.com/ubuntu plucky-updates/main amd64 Packages
  vim-tiny | 2:9.1.0967-1ubuntu4.1 | http://security.ubuntu.com/ubuntu plucky-security/main amd64 Packages
  vim-tiny | 2:9.1.0967-1ubuntu4 | http://archive.ubuntu.com/ubuntu plucky/main amd64 Packages

Use this output when you only need the package name, version, repository, and architecture.


4. Find Available Versions with apt list -a

apt list -a package is another readable way to list versions.

bash
apt list -a vim-tiny

Tested output:

text
Listing...
vim-tiny/plucky-updates,plucky-security,now 2:9.1.0967-1ubuntu4.1 amd64 [installed,automatic]
vim-tiny/plucky 2:9.1.0967-1ubuntu4 amd64

This is useful for quick terminal checks. For scripts, prefer apt-cache policy or apt-cache madison.


5. Check the Installed Package Version

Use dpkg-query to check the installed version before making changes.

bash
dpkg-query -W -f='Package: ${binary:Package}\nVersion: ${Version}\nStatus: ${db:Status-Abbrev}\n' vim-tiny

Tested output:

text
Package: vim-tiny
Version: 2:9.1.0967-1ubuntu4.1
Status: ii

The ii status means the package is installed and configured. For more package database examples, see the dpkg command examples.


6. Simulate Installing a Specific Version

Before installing an exact version, simulate the transaction. This example simulates installing the already installed version.

bash
apt-get install --simulate "vim-tiny=2:9.1.0967-1ubuntu4.1"

Tested output:

text
Reading package lists...
Building dependency tree...
Reading state information...
vim-tiny is already the newest version (2:9.1.0967-1ubuntu4.1).
vim-tiny set to manually installed.
Solving dependencies...
0 upgraded, 0 newly installed, 0 to remove and 51 not upgraded.

If the simulation looks correct, the real install command would be:

bash
sudo apt install "vim-tiny=2:9.1.0967-1ubuntu4.1"

Use quotes when the version contains characters such as : or ~. Quoting avoids shell interpretation issues.


7. Simulate an Older Version and Review Dependency Conflicts

Installing an older version may require matching dependency versions. This simulation tries to install the older vim-tiny version by itself:

bash
apt-get install --simulate "vim-tiny=2:9.1.0967-1ubuntu4"

Tested output:

text
Reading package lists...
Building dependency tree...
Reading state information...
Solving dependencies...
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 vim-tiny : Depends: vim-common (= 2:9.1.0967-1ubuntu4) but 2:9.1.0967-1ubuntu4.1 is to be installed
E: Unable to correct problems, you have held broken packages.
E: The following information from --solver 3.0 may provide additional context:
   Unable to satisfy dependencies. Reached two conflicting decisions:
   1. vim-tiny:amd64=2:9.1.0967-1ubuntu4 is selected as a downgrade
   2. vim-tiny:amd64=2:9.1.0967-1ubuntu4 Depends vim-common (= 2:9.1.0967-1ubuntu4)
      but none of the choices are installable:
      - vim-common:amd64=2:9.1.0967-1ubuntu4 is not selected for install

The key message is that vim-tiny requires a matching vim-common version. This is common when packages are split into binaries, libraries, and common data packages.


8. Simulate Installing Matching Dependency Versions

When APT reports a matching dependency requirement, include the dependency version in the same command.

bash
apt-get install --simulate "vim-tiny=2:9.1.0967-1ubuntu4" "vim-common=2:9.1.0967-1ubuntu4"

Tested output:

text
Reading package lists...
Building dependency tree...
Reading state information...
Solving dependencies...
The following package was automatically installed and is no longer required:
  libsodium23
Use 'apt autoremove' to remove it.
The following packages will be REMOVED:
  vim vim-runtime
The following packages will be DOWNGRADED:
  vim-common vim-tiny
0 upgraded, 0 newly installed, 2 downgraded, 2 to remove and 51 not upgraded.
Remv vim [2:9.1.0967-1ubuntu4.1]
Remv vim-runtime [2:9.1.0967-1ubuntu4.1]
Inst vim-tiny [2:9.1.0967-1ubuntu4.1] (2:9.1.0967-1ubuntu4 Ubuntu:25.04/plucky [amd64]) []
Inst vim-common [2:9.1.0967-1ubuntu4.1] (2:9.1.0967-1ubuntu4 Ubuntu:25.04/plucky [all])
Conf vim-tiny (2:9.1.0967-1ubuntu4 Ubuntu:25.04/plucky [amd64])
Conf vim-common (2:9.1.0967-1ubuntu4 Ubuntu:25.04/plucky [all])

This simulation resolves the direct version dependency, but it would remove vim and vim-runtime. That is why simulation is important: a command can be technically solvable and still be a bad operational choice. After package changes, you may also need to review unused packages in Ubuntu or obsolete packages in Ubuntu.


9. Handle Version Not Found Errors

If you type a version that is not available from enabled repositories, APT reports that the version was not found.

bash
apt-get install --simulate "vim-tiny=0.0-does-not-exist"

Tested output:

text
Reading package lists...
Building dependency tree...
Reading state information...
Package vim-tiny is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Version '0.0-does-not-exist' for 'vim-tiny' was not found

Common causes:

  • The package list is stale; run sudo apt update.
  • The repository that contains that version is not enabled.
  • The version string was copied incorrectly.
  • The package version is for another Ubuntu/Debian release.
  • The package was removed or superseded.

If you must fetch a package file manually, use trusted repositories and verify the source. The guides for downloading files from Linux, wget command examples, and curl command examples can help with manual downloads, but APT repositories are safer for dependency resolution.


10. Hold a Package After Installing a Specific Version

If you install a specific version and do not want APT to upgrade it automatically, hold the package.

bash
sudo apt-mark hold vim-tiny
apt-mark showhold

Tested output:

text
vim-tiny set on hold.
vim-tiny

When you want normal upgrades again, unhold it:

bash
sudo apt-mark unhold vim-tiny

Tested output:

text
Canceled hold on vim-tiny.

The test host was restored to no hold for vim-tiny after this check.


11. When to Use apt Preferences Instead of apt-mark hold

apt-mark hold is simple and works well for one package. For more controlled version selection, use APT preferences in /etc/apt/preferences or /etc/apt/preferences.d/.

Use preferences when you need to:

  • Prefer packages from one repository over another.
  • Pin a package to a release or version pattern.
  • Prevent accidental upgrades across many related packages.
  • Keep a downgrade in place while still allowing selected security updates.

APT pinning is more advanced than a one-line install command, so test it carefully with apt-cache policy package and APT simulations.


Frequently Asked Questions

1. What is the syntax to install a specific version with apt?

Use sudo apt install package=version, replacing package and version with values shown by apt-cache policy, apt-cache madison, or apt list -a.

2. How do I find available versions of an apt package?

Use apt-cache policy package, apt-cache madison package, or apt list -a package to see versions available from enabled repositories.

3. Should I use apt or apt-get in scripts?

Use apt-get in scripts because apt warns that its CLI is not stable for scripting. For interactive terminal use, apt is fine.

4. How can I test installing a specific version without changing the system?

Use apt-get install --simulate package=version to preview what APT would install, downgrade, remove, or keep.

5. Why does apt say version was not found?

The version is not available from enabled repositories, the package lists are stale, the package name is wrong, or the version belongs to a repository that is not configured.

6. How do I stop apt from upgrading a package after installing a specific version?

Use sudo apt-mark hold package to hold the package and sudo apt-mark unhold package when you want upgrades again.

Summary

To install a specific version with APT, first find available versions with apt-cache policy, apt-cache madison, or apt list -a. Then simulate the exact install with apt-get install --simulate package=version. If the simulation is safe, run sudo apt install package=version or sudo apt-get install package=version.

If APT reports dependency conflicts, include matching dependency versions only after reviewing what APT plans to remove, downgrade, or keep. If you need the package to stay on that version, use apt-mark hold or a proper APT preferences file.

For RPM-based systems, see YUM install specific version of package and RPM downgrade with yum or rpm.

Omer Cakmak

Linux Administrator

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 …