installed-packages

You might prefer to have a clean system on reinstall but sometimes it is nice to reinstall applications from a previous machine/setup. Keeping a backup list of packages will make this a snap. Just give your package manager a list of all the packages you want it to install and let it rip.

Here are the backup and restore methods for each of the major distros/package managers.

Debian / Ubuntu

Backup

dpkg –get-selections > installed-software.log

Restore

dpkg –set-selections < installed-software.log
apt-get dselect-upgrade

Arch Linux

Backup

pacman -Qqe | grep -v “$(pacman -Qmq)” > pkglist

Restore

pacman -S $(cat pkglist)

Fedora

Backup

rpm -qa > installed-software.bak

Restore

yum -y install $(cat installed-software.bak)

Gentoo

Backup

cp /var/lib/portage/world installed-software.bak

Restore

cat installed-software.bak | xargs -n1 emerge -uv

OpenSuse

Backup

rpm -qa –queryformat ‘%{NAME} ‘ > installed-software.bak

Restore

sudo zypper install $(cat installed-software.bak)

Subscribe via Email

Subscribe to Nixtutor via Email

Enter your email address:

Was this information useful?

15 Responses

  1. Eric Wendelin

    6-24-2009

    How could you ever do this on Windows? You’d basically have to Ghost (or whatever) an entire drive. Linux FTW!

  2. Erlend

    6-24-2009

    openSuse:

    rpm -qa –queryformat ‘%{NAME} ‘ > installed-software.bak

    sudo zypper install $(cat installed-software.bak)

  3. Mark Sanborn

    6-24-2009

    Thanks Erlend! I added your section to the post. :)

  4. fiber

    6-24-2009

    Awesome list…. just a note: you have a stray ” in the restore lines for Debian/Ubuntu

  5. Mark Sanborn

    6-24-2009

    Fiber, I don’t know where that came from ;) fixed.

  6. Eric Floehr

    6-24-2009

    Fedora has a daily cron task to take an installed package snapshot, and saves to /var/log/rpmpkgs, so just backup that file every day.

  7. Siilex

    6-24-2009

    The solution proposed for Debian lists too many packages.
    I usually use this, which is an improvement:
    dpkg –get-selections | grep “\binstall\$” | cut -f 1 | while read f ; do c=$(apt-cache rdepends “$f” –installed | wc -l) ; if (($c == 2)) ; then echo -e “$f” ; fi ; done
    This oneliner shows the ‘root’ packages between installed ones. ‘Root’ means they do not have other packages depending on them.
    This makes the minimal subset of ‘apt-get install’ targets to get a system like the actual.
    Please, notice metapackages are always shown as root, because nobody depends on them. So the result still has some redundancy.
    Enjoy it.

  8. sufehmi

    6-24-2009

    I usually also backup the /etc

    So when we restore, the reinstalled software will be already configured as it were

    backup :
    tar cvf config.tar /etc

    restore :
    tar xvf config.tar

  9. R

    6-24-2009

    Super handy

  10. Johannes

    6-25-2009

    And do you know how to do this on a FreeBSD machine? I think it’s possible too, but I don’t know how.

    Nice site! Thanks for posting!

  11. anechoic

    6-26-2009

    the line:
    ‘dpkg –get-selections > installed-software.log’

    should be:
    ‘dpkg –get-selections > installed-software.log’

    the M dash ‘–’ is replaced with two ‘–’

    :)

    ***also, you can export markings in Synaptic which pr0lly does the same thing under the hood

  12. Mark Sanborn

    6-28-2009

    Good question, I will see if I can dig up some information for you. :)

  13. Rob

    8-3-2009

    Sorry to sound like an obvious noob but in order for the restore to work you would also need a backup of the sources.list correct?

  14. Mark Sanborn

    8-3-2009

    Rob,
    If you use extra repositories it would be a good idea to back it up.

  15. zone

    2-6-2010

    nice article…learning a lot from here…