How to fix E: Packages were downgraded and -y was used without --allow-downgrades in APT
This error occurs when apt attempts to downgrade packages using the -y flag without explicitly allowing downgrades. The --allow-downgrades flag is required when using automated yes (-y) with package downgrades.
Quick fix
Fixes E: Packages were downgraded and -y was used without --allow-downgrades
sudo apt install -y --allow-downgrades package-name=version- Add --allow-downgrades flag to your apt command
- For Ansible playbooks, use the allow_downgrade option
- Update your cron or CI/CD scripts to include the flag
- Verify your package versions before downgrading
sudo apt install -y --allow-downgrades package-name=versionE: Packages were downgraded and -y was used without --allow-downgrades
What this error means
APT (Advanced Package Tool) detected that a package downgrade would occur, but you used the -y (automatic yes) flag without including --allow-downgrades. Since package downgrades can potentially break system stability, apt requires explicit permission via the --allow-downgrades flag when combined with automated approval. This safety mechanism prevents accidental downgrades in automated scripts or configurations.
Typical symptoms
- apt install or apt upgrade fails with "E: Packages were downgraded and -y was used without --allow-downgrades"
- Ansible apt module fails when trying to install specific older package versions
- Automated upgrade scripts in cron or CI/CD pipelines fail during package installation
- Docker or other package updates trigger downgrade errors unexpectedly
Common causes
- Using apt with -y flag while attempting to install a version older than what is currently installed
- Ansible apt module with allow_downgrade option but missing the flag in the actual apt command
- Automated upgrade scripts that do not account for dependency changes causing package versions to downgrade
- Package repository changes where a newer version is no longer available, falling back to an older version
- Docker or third-party package managers upgrading packages outside the normal apt flow, then apt trying to downgrade them back
How to fix "E: Packages were downgraded and -y was used without --allow-downgrades"
When using apt with -y to install a specific older version of a package, include the --allow-downgrades flag:
sudo apt install -y --allow-downgrades package-name=versionExample:
sudo apt install -y --allow-downgrades docker-ce=5.20.10~3-0~ubuntu-focalIf you are using Ansible, ensure your apt module includes the allow_downgrade parameter:
- name: Install specific package version
ansible.builtin.apt:
name: "{{ package_name }}={{ package_version }}"
state: present
allow_downgrade: yesNote: Even with allow_downgrade set, you may need to ensure the generated apt command includes --allow-downgrades for Ansible versions that have this limitation.
If running automated upgrades via cron or CI/CD pipelines, modify your upgrade command:
Old (failing):
apt update && apt upgrade -yNew (if downgrades are needed):
apt update && apt upgrade -y --allow-downgradesBetter alternative - use unattended-upgrades:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgradesThe unattended-upgrades package handles version conflicts intelligently without manual flag management.
Before applying the --allow-downgrades flag, understand why the downgrade is happening:
# Check currently installed version
apt list --installed | grep package-name
# Check available versions in repositories
apt policy package-name
# Check what apt would do with a dry run
apt install -y --allow-downgrades --simulate package-name=versionOnly proceed with the actual installation if the simulation looks correct.
Advanced notes
The --allow-downgrades flag was introduced in APT 1.1 as a replacement for the deprecated --force-yes option, which was considered too permissive. The --allow-downgrades flag is intentionally strict because downgrading packages can introduce dependency conflicts and break system stability. In production environments, prefer using unattended-upgrades over manual apt commands, as it intelligently handles version conflicts. If you frequently need to downgrade packages, consider investigating why (e.g., Docker version incompatibilities, conflicting package sources) and address the root cause rather than treating downgrades as a routine operation. On systems with multiple package sources, pin specific packages using /etc/apt/preferences to prevent unexpected downgrades.
Frequently asked questions
- What does "E: Packages were downgraded and -y was used without --allow-downgrades" mean?
- APT (Advanced Package Tool) detected that a package downgrade would occur, but you used the -y (automatic yes) flag without including --allow-downgrades. Since package downgrades can potentially break system stability, apt requires explicit permission via the --allow-downgrades flag when combined with automated approval. This safety mechanism prevents accidental downgrades in automated scripts or configurations.
- How do I fix "E: Packages were downgraded and -y was used without --allow-downgrades"?
- This error occurs when apt attempts to downgrade packages using the -y flag without explicitly allowing downgrades. The --allow-downgrades flag is required when using automated yes (-y) with package downgrades.
- What causes "E: Packages were downgraded and -y was used without --allow-downgrades"?
- Using apt with -y flag while attempting to install a version older than what is currently installed Ansible apt module with allow_downgrade option but missing the flag in the actual apt command Automated upgrade scripts that do not account for dependency changes causing package versions to downgrade
- Is the "E: Packages were downgraded and -y was used without --allow-downgrades" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐APT Official Documentation
- ๐
- ๐
- ๐
- ๐Ubuntu - apt-get manual page(Official Docs)