Hardware and software failures are part of life. And that is why you need to have a backup plan. I have already written about backing up files and MySQL databases. There is no need to backup all installed binaries and software programs. The following tip will not just save your time, but both Debian/Ubuntu and CentOS/Fedora/RHEL based distro can be updated and restored when required.

In order to reinstall or restore your installed software you need to have a list of all installed software. The package manager in Linux can be used to save installed/removed packages on a source system and duplicate those changes on other systems. This post will help you through do the same.

HowTo: Create a Backup list of all installed software on a Debian / Ubuntu Linux

If you are using a Debian or Ubuntu Linux, use the dpkg command to list installed software:
$ dpkg --get-selections
You can store list of installed software to a file called /backup/installed-software.log, enter:
$ dpkg --get-selections > /backup/installed-software.log

HowTo: Create a Backup list of all installed software on a RHEL/Fedora/Suse/CentOS Linux

RPM based distributions (RHEL, Fedora, Redhat, CentOS, Suse Linux) user try the rpm command to get list of all installed software, enter:
$ rpm -qa
OR
$ rpm -qa > /backup/installed-software.log
OR remove software version number (recommended):
rpm -qa --qf "%{NAME}\n" | sort > /backup/installed-software.log

How do I restore installed software from a backup List?

Under a Debian/Ubuntu Linux type the following two commands to reinstall all the programs:
# dpkg --set-selections < /backup/installed-software.log
Once list is imported, use the dselect command or other tools to install the packages, enter:
# dselect
Select ‘i‘ for install the software. OR use the following command:
# apt-get dselect-upgrade

Restoring packages on rpm based distro

As far as I know RPM based distro does not offers dpkg kind of facility. But, with a little shell scripting technique you can easily install all software programs:
# LIST="$ cat /backup/installed-software.log )"
If you are using the yum command, type the following bash for loop to install all software:
# for s in $LIST; do yum -y install $s; done

Or try out the following command (HT to gt):
# yum -y install $(cat /backup/installed-software.log)

A Note About RHEL version 4

If you are using RHEL/CentOS v4.x or older, enter:
# for s in $LIST; do up2date -i $s; done

Alternatively, you can use the following up2date command:
# up2date -i $(cat /backup/installed-software.log)

๐Ÿฅบ Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! ๐Ÿค 
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

55 comments… add one
  • cyrixmorten Nov 18, 2011 @ 20:53

    correcting the command above

    sed -r –in-place ‘s/-[0-9][a-z 0-9_.-]*//’ installed-software.log

  • cyrixmorten Nov 18, 2011 @ 20:55

    correcting the command above

    sed -r –in-place ‘s/-[0-9][a-z 0-9_.-]*//’ installed-software.log

  • Nicholas Blasgen Nov 25, 2011 @ 4:16

    if mount -o remount,exec /tmp && pear channel-update pear.php.net && pear upgrade –force Console_Getopt && pear upgrade –force pear && pear upgrade-all && pecl install json; then
    echo “extension=json.so” > /etc/php.d/json.ini
    mount -o remount,noexec /tmp
    else
    mount -o remount,noexec /tmp
    error_exit “JSON was unable to be installed”
    fi

  • prasanna Jan 9, 2012 @ 10:50

    Is there any way to get the software manufacturer name with dpkg/rpm command for those softwares.

  • cmcanulty Jan 13, 2012 @ 18:02

    I run the 1st command and get the list but on the second command
    i get this this error
    “cmcanulty@Darcy25:~$ dpkg –get-selections > /backup/installed-software.log
    bash: /backup/installed-software.log: No such file or directory”
    but I did make a bckup folder in my home and created a test file called
    installed-software.log before I ran the 2nd command what am I doing wrong?

    • kohrime Jan 28, 2012 @ 23:58

      Kindly delete the “installed-software.log” that you made (I think).

      Home’s directory is actually /home//

      Maybe try doing this command instead:
      dpkg รขโ‚ฌโ€œget-selections > ~/backup/installed-software.log

  • tw Mar 4, 2012 @ 15:27

    Hey all, little trouble here, hopefully I didn’t just jack up like I think I might have…
    I created the .log file and saved it, all my docs/files and a febe file for firefox to flash before install of precise pangolin beta, I tell it to:
    # dpkg –set-selections < /backup/installed-software.log after recreating the location and placing the file there where it should be…net result:0 , it didn't pull the packages
    Any ideas on what to do now?

    • tw Mar 4, 2012 @ 19:45

      I am thinking I should still be using dpkg but with the refuse downgrade command in conjunction with the set selections command to reinstall all my packages from before, but apparantly I’m not getting that right…

  • Jas Jun 6, 2012 @ 17:34

    hi
    i have remove vnc RPM`s from my Linux Server & again install it but its not working,when i try to open
    #vino-preferences its not working
    can someome please tell why this heppning

  • bodhi.zazen Jul 6, 2012 @ 21:47

    Small suggestion on your rpm backup strategy –

    rpm -qa

    Includes package version numbers, which are subject to change.

    You can strip them with a “simple” modification

    rpm -qa --qf "%{NAME}n" | sort > /backup/installed-software.log

    Restore is the same (careful with the -y):

    yum -y install $(cat /backup/installed-software.log)
  • AAMAA Sep 24, 2013 @ 20:15

    Please help
    When I try to update
    Or the installation of any tool
    Always having a this message
    root@bt:~# apt-get install software-center
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Couldn’t find package software-center
    I’ve tried a lot of solutions to no avail

  • Richard Couvillon Sep 8, 2016 @ 1:15

    There is another line that should be run before restoring the list to dselect:
    sudo dselect update

    Without this line, about 1000 entries to the list throw an error – not in database.
    After running the dselect update, then bringing the list into dselect, there are only 2 files which are not reloaded. They are not in the Synaptic List and are downloaded from providers. Google Chrome being one of them.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.