sábado, 26 de outubro de 2019

How to recover packages to local cache - Ubuntu

I had to sudo apt clean my local cache to uninstall a bad package and needed to recover my installed packages since I work often in offline places, so that I can recover from a broken system without Internet.

So be able to recover, or better, re-download packages to local cache that usually is located at: /var/cache/apt/archives  we have this:

1) get install package names:

dpkg -l | grep "^ii" | awk ' {print $2} ' > pkg_names.txt

2) get install package versions:

dpkg -l | grep "^ii" | awk ' {print $3} ' > pkg_version.txt

3) combine package names and versions

paste -d"=" pkg_names.txt pkg_version.txt > pkg_combine.txt

4) now re-download packages to cache

cat pkg_combine.txt | xargs sudo apt-get -y install --reinstall --download-only


dpkg -l | grep "^ii"| awk ' {print $2} ' | xargs sudo apt-get -y install --reinstall --download-only

dpkg -s firefox | grep Version | awk ' {print $2} '

sudo apt-get install package=version


Timeout each line to avoid long loops (when source is dead or pkg not available at repository)

Nenhum comentário:

Postar um comentário