apt-get / dpkg
- Advanced Package Tool - apt-get man page
- Debian Package - dpkg man page
- apt vs dpkg:
dpkgis .. the low-level package manager, it (deals with the) .deb files, BUT does not perform dependency resolution. On the other hand,aptis a high (abstraction level) package manager.aptdeals with dependencies and can retrieve packages from the online repositories.
List Packages Installed
apt list --installed
Identify the Package That Owns the File
dpkg -S /bin/ls
Waiting on the apt/dpkg locks
#!/usr/bin/env bash
#
# Wait for all known dpkg locks
#
function apt_wait () {
while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
echo "Waiting on /var/lib/dpkg/lock..."
sleep 1
done
while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1 ; do
echo "Waiting on /var/lib/dpkg/lock-frontend..."
sleep 1
done
while sudo fuser /var/lib/apt/lists/lock >/dev/null 2>&1 ; do
echo "Waiting on /var/lib/apt/lists/lock..."
sleep 1
done
if [ -f /var/log/unattended-upgrades/unattended-upgrades.log ]; then
while sudo fuser /var/log/unattended-upgrades/unattended-upgrades.log >/dev/null 2>&1 ; do
echo "Waiting on /var/log/unattended-upgrades/unattended-upgrades.log..."
sleep 1
done
fi
# FIXME: wait for /var/cache/apt/archives/lock
# /var/cache/apt/archives/lock
}
#
# to avoid "Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 5475 (unattended-upgr)"
#
apt_wait
Specify lock timeout on the command line
APT_GET_OPTIONS="-o DPkg::Lock::Timeout=60"
sudo apt-get "${APT_GET_OPTIONS}" install -y _package_
Clean-up
Free space in /var/cache/apt/archives/ - from most to least conservative…
Remove Unused Dependencies - removes packages that were installed as dependencies but are no longer needed:
apt autoremove
Partial (Conservative) Clean - removes only outdated package files that can no longer be downloaded.
apt autoclean
Total Clean - recommended for space - removes all downloaded .deb package files from the cache.
apt clean