Understanding the Error
E: Could not get lock /var/lib/apt/lists/lock
E: Could not get lock /var/cache/apt/archives/lock
Fix 1: Kill the Process Holding the Lock
# Find PID
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock
# Kill process
sudo kill -9 PID
# Remove lock files
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock-frontend
Fix 2: One-Liner to Clear All Locks
sudo killall apt apt-get 2>/dev/null; sudo rm /var/lib/apt/lists/lock /var/cache/apt/archives/lock /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock; sudo dpkg --configure -a
Fix 3: Disable Unattended Upgrades Temporarily
sudo systemctl stop unattended-upgrades
# Run your apt command
sudo systemctl start unattended-upgrades
Fix 4: Reboot
If all else fails, reboot clears all locks:
sudo reboot
Fix 5: Use Force Option (Not Recommended)
# Use with caution
sudo rm -rf /var/lib/apt/lists/*
sudo apt update
After clearing locks, update package lists:
sudo apt update