Skip to content

Instantly share code, notes, and snippets.

@volkbay
Last active July 6, 2023 15:10
Show Gist options
  • Save volkbay/19122336c6dffe7def3e7fc5446900bd to your computer and use it in GitHub Desktop.
Save volkbay/19122336c6dffe7def3e7fc5446900bd to your computer and use it in GitHub Desktop.
Fix kept back packages issues of apt

👾 Error

...
The following packages have been kept back:
...

🤔 Why do I see this error ?

This may be caused by phased updates or changed dependencies.

🔎 How to solve ?

Note Alternative solutions exits, but they may remove dependencies. Please check this issue.

It is best to run this script after doing apt upgrade, so only kept-back packages would be collected. This script checks if collected packages are automatically installed. After manual installation of all kept-back ones, respective one are marked back to auto.

🕊️ Solution See attached .sh file.

#!/bin/sh
# Author: volkbay[2023]
#
# Please run this script, *after* doing `apt upgrade`.
file='.apt_keptback'
file2='.apt_auto'
file3='.apt_auto_kept_back'
# Gather kept back packages
sudo apt list --upgradable > $file
sed -ri 's/(^.*)(\/)(.*)/\1/g' $file
sed -i 1d $file
# Gather manually installed packages
sudo apt-mark showauto > $file2
# Compare 1-by-1 and take common packages in two files
touch $file3
> $file3
while read x; do grep $x $file2 >> $file3; done < $file
# Install all kept-back packages
xargs sudo apt install -y < $file
# Mark auto packages
xargs sudo apt-mark auto < $file3
# Remove files
rm $file $file2 $file3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment