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.
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:
sudo apt install package=versionUse the stable apt-get interface for scripts or automation:
sudo apt-get install package=versionPreview the exact-version install without changing the system:
apt-get install --simulate package=versionFor 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.
sudo apt updateTested output:
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.
apt-cache policy vim-tinyTested output:
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 PackagesIn this output:
Installedis the version currently installed.Candidateis the version APT would normally install or upgrade to.- The version table shows other available versions and their repositories.
2:9.1.0967-1ubuntu4.1includes 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.
apt-cache madison vim-tinyTested output:
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 PackagesUse 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.
apt list -a vim-tinyTested output:
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 amd64This 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.
dpkg-query -W -f='Package: ${binary:Package}\nVersion: ${Version}\nStatus: ${db:Status-Abbrev}\n' vim-tinyTested output:
Package: vim-tiny
Version: 2:9.1.0967-1ubuntu4.1
Status: iiThe 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.
apt-get install --simulate "vim-tiny=2:9.1.0967-1ubuntu4.1"Tested output:
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:
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:
apt-get install --simulate "vim-tiny=2:9.1.0967-1ubuntu4"Tested output:
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 installThe 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.
apt-get install --simulate "vim-tiny=2:9.1.0967-1ubuntu4" "vim-common=2:9.1.0967-1ubuntu4"Tested output:
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.
apt-get install --simulate "vim-tiny=0.0-does-not-exist"Tested output:
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 foundCommon 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.
sudo apt-mark hold vim-tiny
apt-mark showholdTested output:
vim-tiny set on hold.
vim-tinyWhen you want normal upgrades again, unhold it:
sudo apt-mark unhold vim-tinyTested output:
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?
2. How do I find available versions of an apt package?
3. Should I use apt or apt-get in scripts?
4. How can I test installing a specific version without changing the system?
5. Why does apt say version was not found?
6. How do I stop apt from upgrading a package after installing a specific version?
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.

