When working with Debian-based systems, you'll occasionally encounter scenarios where package dependencies create version conflicts. Imagine this situation:
# Current state:
Package B installed: v2.1
Package A requires: B (>2.0)
# Repository contains:
Package B available: v2.2
While your system technically meets the dependency requirement (2.1 > 2.0), APT will still try to upgrade to the newest available version (2.2) during installation.
The most straightforward method is to use APT's built-in flag:
sudo apt-get install --no-upgrade package-A
This tells APT to:
- Install package A
- Skip any upgrades to already-installed packages
- Only install missing dependencies
For more permanent control, use package pinning:
# Hold the current version of package B
sudo apt-mark hold package-B
# Now install package A
sudo apt-get install package-A
# Optional: remove the hold later
sudo apt-mark unhold package-B
Create /etc/apt/preferences.d/package-B with:
Package: package-B
Pin: version 2.1*
Pin-Priority: 1001
This configuration:
- Locks package B at version 2.1
- Sets priority higher than standard packages (1001)
- Overrides repository versions
A common scenario involves PHP extensions:
# Current PHP version: 7.4
# Repository has PHP 8.0
# Want to install a package requiring php7.4-*
sudo apt-mark hold php7.4
sudo apt-get install --no-upgrade package-requiring-php
Remember that preventing upgrades might:
- Leave security vulnerabilities unpatched
- Cause future compatibility issues
- Require manual intervention for subsequent updates
Always test in a development environment before applying these changes to production systems.
When working with Debian-based systems, we often encounter this scenario:
sudo apt-get install packageA
The following packages will be upgraded:
packageB
Even though our current version of packageB (say 2.1) already satisfies packageA's dependency requirement (>2.0), APT insists on upgrading to the latest version (2.2) available in repositories.
By default, APT will:
- Resolve all dependencies to their newest available versions
- Consider recommended packages as dependencies (configurable)
- Upgrade all packages in the dependency chain to maintain consistency
1. Using --no-upgrade
The most straightforward approach:
sudo apt-get install packageA --no-upgrade
However, this has limitations - it prevents ALL upgrades during installation, not just specific dependencies.
2. Pinning Specific Package Versions
More surgical approach using apt-mark:
sudo apt-mark hold packageB
sudo apt-get install packageA
sudo apt-mark unhold packageB
Or using /etc/apt/preferences.d/:
Package: packageB
Pin: version 2.1*
Pin-Priority: 1001
3. Using aptitude's Interactive Mode
Aptitude provides more granular control:
sudo aptitude install packageA
Then press 'n' to reject the upgrade proposal and find alternative solutions.
4. Forcing Specific Dependency Versions
Using apt-get with version pinning:
sudo apt-get install packageA packageB=2.1
Creating a Local Minimal Repository
For critical production systems:
mkdir ~/local-repo
cd ~/local-repo
apt-get download packageB=2.1
sudo dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz
Then add to /etc/apt/sources.list:
deb [trusted=yes] file:/home/user/local-repo ./
Using equivs for Virtual Packages
When you need to fake dependency satisfaction:
sudo apt-get install equivs
equivs-control packageB-virtual
# Edit the control file
equivs-build packageB-virtual
sudo dpkg -i packageB-virtual.deb
- Partial upgrades may break system consistency
- Held packages might conflict with security updates
- Manual version pinning requires maintenance
- Always test in a staging environment first
- Document all version constraints applied
- Monitor security advisories for held packages
- Consider using containers for isolation