Automated reinstall of software from package list

Last modified on July 24, 2026 • 1 min read • 140 words
If I need to reinstall a Ubuntu/Debian-based Linux OS (or mirror a software selection to another machine), this is how it can be done.
If I need to reinstall a Ubuntu/Debian-based Linux OS (or mirror a software selection to another machine), this is how it can be done. On the source machine:sudpkg --get-selections > ~/Package.listcp -R /etc/apt/sources.list* ~/apt-key exportall > ~/repository.keysThen just copy the files to the target machine:suapt-key add ~/repository.keyscp -R ~/sources.list* /etc/apt/apt-get updateapt-get install dselectdselect updatedpkg --set-selections < ~/Package.listapt-get dselect-upgrade -yIf some packages are not available, this will fail. This concerns in my case manually installed packages like teamviewer  or snapgene  / snapgene_viewer  . I usually remove those packages manually from the list (there are luckily not many of them).However, the upgrade is not fully automatic, since you need to e.g. agree to various licenses (e.g. for Microsoft’s True Type fonts) and acknowledge manually other stuff (e.g. libdvd-pkg legal issues), which kind of defeats the purpose of making this automatic and painless…