When working with Debian-based systems, APT (Advanced Package Tool) maintains metadata about package installation states. Each package is marked as either:
- Automatically installed: Installed as a dependency of another package
- Manually installed: Explicitly requested by the user
# Example output showing installation status
$ apt-mark showmanual | grep zlib1g-dev
zlib1g-dev
During development, you might explicitly install a package that was previously auto-installed as a dependency. After completing your task, you want to revert this status change to maintain system cleanliness.
The correct way to change the status is using the apt-mark
command:
# Mark package as automatically installed
$ sudo apt-mark auto zlib1g-dev
# Verify the change
$ apt-mark showmanual | grep zlib1g-dev
[No output means success]
If you prefer aptitude's interactive interface:
$ sudo aptitude
> Search for zlib1g-dev
> Press 'M' to toggle manual/auto status
> 'q' to quit
These commands modify /var/lib/apt/extended_states
, which stores the auto-installed status. While you could edit this file directly:
Package: zlib1g-dev
Auto-Installed: 1
It's better to use the official tools to ensure proper database consistency.
Properly marked packages allow efficient system cleanup:
# Safely remove unneeded dependencies
$ sudo apt-get autoremove
This helps keep your development environment clean and avoids accumulating unnecessary packages.
Here's a complete example for a typical development scenario:
# 1. Check initial status
$ apt-mark showauto zlib1g-dev
[No output means manual]
# 2. Compile your project
$ make
# 3. Mark the dependency as auto when done
$ sudo apt-mark auto zlib1g-dev
# 4. Later cleanup
$ sudo apt-get autoremove
When you explicitly install a package that was previously auto-installed as a dependency, APT changes its status to "manually installed". This prevents apt-get autoremove
from cleaning it up later, even when no other packages depend on it.
# Original state (auto-installed as dependency)
$ apt-get install zlib1g-dev
zlib1g-dev is already the newest version.
zlib1g-dev set to manually installed.
Instead of manually editing /var/lib/apt/extended_states
, use the official tool:
# Mark as auto-installed
sudo apt-mark auto zlib1g-dev
# Verify the change
apt-mark showauto zlib1g-dev
APT maintains two lists of packages:
- Manual:
apt-mark showmanual
- Auto:
apt-mark showauto
You can check all dependencies that pulled in your package:
apt-cache rdepends --installed zlib1g-dev
Here's how I handle temporary build dependencies:
# 1. Check current status
apt-mark showmanual | grep zlib1g-dev
# 2. Temporarily install for compilation
sudo apt-get install zlib1g-dev
# 3. After build completes, reset to auto
sudo apt-mark auto zlib1g-dev
# 4. Later cleanup when safe
sudo apt-get autoremove
For multiple packages, use xargs:
# Reset all dev packages to auto
dpkg -l | grep '\-dev' | awk '{print $2}' | xargs sudo apt-mark auto
While editing /var/lib/apt/extended_states
works, it's risky because:
- APT may overwrite your changes during operations
- No validation of package names
- Requires manual cache updates
The proper sequence if you must edit manually:
sudo nano /var/lib/apt/extended_states
sudo apt-get update