Package managers on Ubuntu and Debian grab the latest release by default. Sometimes that’s not what you want. You may need an older build or a version tied to a specific dependency chain. The apt install specific version command lets you pick exactly which build goes on your machine. This guide covers checking available versions, installing the right one, and locking it so future updates don’t overwrite your choice.
Why You Would Apt Install Specific Version
A newer release can break compatibility with your stack. Your deployment pipeline may require a fixed build that passed QA. On older servers, a dated package might be the only option that avoids unwanted upgrades. If you’re new to Debian-based package management, the apt-get command reference is a good starting point.
Update Your Package Index
Pull the latest metadata from your configured repositories first:
sudo apt update
Skipping this step can cause version lookups to return stale or incomplete results.
Check Available Versions
Use apt-cache policy to list every obtainable build. Replace nginx with your target package:
apt-cache policy nginx
| Field | Meaning |
|---|---|
| Installed | The build currently on your machine (or “none”) |
| Candidate | The default build apt would grab |
| Version table | All obtainable builds with priority scores |
Apt Install Specific Version of a Package
Pass the exact build string with an equals sign:
sudo apt install nginx=1.20.2-1ubuntu2
Copy the version string character-for-character from apt-cache policy output. The general syntax:
sudo apt install package-name=version-string
Hold the Package to Block Automatic Upgrades
After you apt install specific version, a routine apt upgrade can overwrite it. Lock the package with apt-mark:
sudo apt-mark hold nginx
To allow upgrades again later:
sudo apt-mark unhold nginx
Verify the Build and Troubleshoot Problems
Run apt-cache policy nginx to confirm the “Installed” line matches your target build. If something went wrong:
| Problem | Fix |
|---|---|
| Version not found | Run sudo apt update. The version may live in a repo you haven’t enabled. |
| Dependency conflicts | Try sudo aptitude install package=version for alternative resolution. |
| Pinned priority blocking | Force with sudo apt install package=version --allow-downgrades. |
Tips Before You Start
Back up your system before swapping builds. For programming libraries, tools like virtualenv or conda isolate dependencies without touching system packages. See the dpkg man page for lower-level inspection, and if apt isn’t working, check the guide on fixing apt-get command not found.
FAQs
Can I install multiple specific package versions at once?
Yes. Separate each pair with a space: sudo apt install pkg1=version1 pkg2=version2. Fails if any package has unmet dependencies.
Does apt install specific version work the same as apt-get?
Yes. Both accept package=version syntax and behave identically for pinned installs.
How do I downgrade a package to an older version?
Use sudo apt install package=older-version. Add --allow-downgrades if apt blocks the operation.
What if the version I need is not in any repository?
Add a PPA or third-party repo that carries it, or download the .deb file and install with sudo dpkg -i package.deb.
Will holding a package cause problems during system upgrades?
Held packages are skipped during upgrades. This can trigger dependency warnings. Monitor holds with apt-mark showhold.