Automatically marks Debian/Ubuntu packages as auto-installed, which may help reduce conflicts during dist-upgrade.
During dist-upgrade, you may encounter package conflicts when the packaging structure changes:
1. Package Split/Merge Conflicts
When packages are split or merged between releases, APT cannot automatically handle the transition if the old package is marked as manually installed. This causes conflicts because APT cannot remove the old package to install the new one.
Example: Package foo, which is depends by an iportant package bar, is split into foo-core and foo-utils. If foo is manually installed, APT cannot automatically remove it and install the split packages.
2. Library Repackaging
Libraries often get renamed with version numbers (e.g., libssl1.1 to libssl3). Manually installed old versions accumulate over time and cannot be auto-removed, even when no longer needed.
3. Transitional Package Cleanup
Transitional packages are temporary packages used during upgrades to help migration. If marked as manually installed, they remain on the system indefinitely after serving their purpose.
This tool marks packages as automatically installed when they are dependencies of other packages, while preserving your explicitly chosen packages (whitelist). This may help APT's dependency resolver better handle package reorganization during upgrades.
Key behavior:
- Packages with reverse dependencies (depended upon by other packages) -> marked auto
- Packages in whitelist -> remain manual
- Orphaned packages (not depended upon by anything) -> remain manual
In most cases, this means apt-get autoremove will not remove any packages, but package reorganization during upgrades may work more smoothly.
- Reads your whitelist configuration
- Queries all manually installed packages
- For each manual package, checks if other packages depend on it
- Marks packages with dependencies (but not in whitelist) as auto
- Orphaned packages remain manual to prevent accidental removal
git clone https://github.com/raohwork/apt-aggressive-mark.git
cd apt-aggressive-mark
chmod +x apt-aggressive-mark
# Copy example config
cp config.example ~/.config/apt-aggressive-mark.confOr download directly:
wget https://raw.githubusercontent.com/raohwork/apt-aggressive-mark/main/apt-aggressive-mark
chmod +x apt-aggressive-markDry-run (recommended first):
./apt-aggressive-mark --dry-runActually execute:
sudo ./apt-aggressive-markCommon options:
# Dry-run with package list
./apt-aggressive-mark --dry-run --list-manual
# Verbose output for debugging
./apt-aggressive-mark --dry-run --verbose
# Use custom config file
./apt-aggressive-mark --config /path/to/config
# Execute and show resulting manual packages
sudo ./apt-aggressive-mark --list-manualAll options:
-h, --help Show help message
-c, --config CONFIG Specify config file path
-d, --dry-run Show what would be done without modifying
-v, --verbose Show detailed execution process
-l, --list-manual List all manual packages after execution
--skip-safety-check Skip safety check (not recommended)
Create ~/.config/apt-aggressive-mark.conf or /etc/apt-aggressive-mark.conf:
# List packages that must remain manually installed
# These are tools you explicitly need for your work
# Text editors
vim
# Terminal tools
tmux
htop
# Version control
git
# Network tools
curl
wget
# Development tools
build-essentialImportant: Only list tools you actively use. Do not list system packages like linux-image-amd64 unless you are extremly sure the package will still be there in the future.
The tool includes multiple safety checks:
- Whitelist verification - Refuses to run if whitelist is empty
- Orphaned package protection - Avoids marking packages that nothing depends on
- Autoremove simulation - Attempts to verify that
apt-get autoremovewill not remove packages after marking - Dry-run mode - Test without making changes
If safety checks fail, the tool stops and displays detailed error messages. However, users should still review changes carefully before applying them on critical systems.
Before dist-upgrade:
sudo apt-aggressive-mark
sudo apt-get dist-upgradeRegular maintenance:
sudo apt-aggressive-mark
sudo apt-get autoremoveFirst-time use workflow:
# 1. Check current state
apt-mark showmanual | wc -l
# 2. Configure whitelist
cp config.example ~/.config/apt-aggressive-mark.conf
vim ~/.config/apt-aggressive-mark.conf
# 3. Test
./apt-aggressive-mark --dry-run --list-manual
# 4. Execute
sudo ./apt-aggressive-mark --list-manual
# 5. Verify
apt-mark showmanual | wc -l # Should typically be less
apt-get autoremove --dry-run # Should typically show no removalsQ: Will this remove any packages?
A: No. The tool only changes package marks (manual/auto). It never removes packages. After running, apt-get autoremove should typically show zero packages to remove (if your whitelist is properly configured).
Q: What if I need to revert?
A: Mark packages back to manual:
apt-mark manual package-nameQ: What should be in my whitelist?
A: Only packages you explicitly installed for your own use:
- Text editors you use
- Command-line tools you use
- Development tools you installed
- Applications you installed
Do not include unless you know what you are doing:
- System packages (kernel, bootloader, init system)
- Libraries
- Dependencies
Q: Why did the safety check fail?
A: Your whitelist may be incomplete. Run with --verbose to see which packages would be removed, then add necessary packages to your whitelist.
Q: Does this affect auto-installed packages?
A: No. It only processes manually installed packages.
Q: Can I use this on production servers?
A: It's possible, but always test with --dry-run first. The tool is designed with safety in mind and includes multiple checks, but as with any system modification tool, caution is advised.
- Python 3 (standard library only)
- APT package management system
- Root privileges for execution (not for dry-run)
GPLv3
Issues and pull requests are welcome.