This error occurs when APT encounters invalid syntax in the /etc/apt/preferences file. The preferences file must follow strict formatting rules with required Package, Pin, and Pin-Priority headers separated by blank lines.
The /etc/apt/preferences file controls package pinning and version prioritization in Debian-based systems. APT parses this file to determine which package versions to prefer during installation and upgrades. When APT detects a line that doesn't conform to the required format—such as missing required headers, incorrect field names, or malformed entries—it reports this error and refuses to continue. Common issues include using 'Priority:' instead of 'Pin-Priority:', using '#' for comments instead of the 'Explanation:' field, leaving the file empty except for comments, or mixing in unrecognized configuration syntax.
Open the file and review its contents carefully:
sudo nano /etc/apt/preferencesEnsure the file follows the required structure:
- Each record starts with 'Package: <package-name>' or 'Package: *'
- Followed by 'Pin: <pin-specification>'
- Followed by 'Pin-Priority: <priority-number>'
- Multiple records are separated by blank lines
- No other content should appear between these fields
Correct these frequent mistakes:
Incorrect Priority field:
# WRONG
Priority: 900
# CORRECT
Pin-Priority: 900Using # for comments:
# WRONG
# This is a comment
# CORRECT
Explanation: This is a commentMissing Package header:
# WRONG
Pin: release a=stable
Pin-Priority: 700
# CORRECT
Package: *
Pin: release a=stable
Pin-Priority: 700A valid preferences file should look like:
Package: nginx
Pin: release a=stable
Pin-Priority: 900
Package: *
Pin: release a=testing
Pin-Priority: 700Key points:
- Each record starts on a new line with 'Package:'
- All three fields (Package, Pin, Pin-Priority) are required
- Records are separated by exactly one blank line
- No spaces or special formatting between lines
After fixing syntax errors, test the file with:
sudo apt-cache policyIf the error persists, check for hidden characters or whitespace issues:
cat -A /etc/apt/preferencesThis shows all special characters, including tabs and carriage returns that might cause parsing issues.
If the file is not needed or corruption is severe, remove it entirely:
sudo rm /etc/apt/preferencesThen verify package management works:
sudo apt updateYou can also check /etc/apt/preferences.d/ directory for additional preference files:
ls -la /etc/apt/preferences.d/Fix or remove any corrupted files in that directory as well.
The /etc/apt/preferences file uses a strict record-based format. Each record must be complete with all required fields. APT also supports a preferences.d directory (/etc/apt/preferences.d/) where you can place multiple preference files with .pref extension. These files are processed in alphanumeric order.
For pin specifications, use 'apt-cache policy <package>' to verify that your pinning rules are correctly applied. The output shows the available versions and their priorities.
When dealing with distribution-based pins, use 'apt-cache policy' output to identify the correct release attribute names (release codenames like 'focal', 'jammy', 'bookworm', or archive names like 'stable', 'testing').
Note that APT reads these files sequentially, so more specific package entries should come before general wildcard entries to ensure proper precedence.
E: Could not connect to proxy server
Could not connect to proxy server
E: Package 'package:i386' has no installation candidate
How to fix "Package package:i386 has no installation candidate" in apt
E: The value 'value' is invalid for APT::Default-Release
How to fix invalid APT::Default-Release value in APT
dpkg: error: unable to create new file 'path': Permission denied
How to fix dpkg permission denied errors in APT
subprocess installed post-removal script returned error exit status 1
How to fix "subprocess installed post-removal script returned error exit status 1" in APT