Create A List Of Installed Packages And Install Them Later From The List In CentOS And Ubuntu

Create A List Of Installed Packages In CentOS and Ubuntu

A few days ago, we have published a guide that described how to create a list of installed packages and install them later from the list in Arch Linux, and its derivatives like Antergos, Manjaro Linux etc. Today, in this guide, we will do the same, but in other popular Linux distributions such as CentOS and Ubuntu. This will be helpful when you want to re-install your Linux system. You don’t have to manually install one by one after re-installing your Linux box. Just take the backup list of installed packages before formatting your system, and and install all at once from the list. This will also be helpful when you wanted to install the same set of softwares on multiple systems running with similar OS.

Recommended DownloadFree eBook: “Learning Python”

Create A List Of Installed Packages In CentOS and install them later

First, we will see how to do it in CentOS system. I tested this guide on CentOS 7 server edition. However, it this method should work on other YUM based distros such as RHEL, Fedora, Scientific Linux etc.

Create the list of installed packages using command:

rpm -qa | sort > pkglist.txt

Here,

  • rpm – RPM Package Manager
  • -qa – Query all installed packages
  • sort – sort lines of text files
  • pkglist.txt – The file where we save the list of installed packages.

The above command will list of all installed packages on your CentOS 7 machine and save them in a file called pkglist.txt in your current working directory.


Recommended Read: ExplainShell – Find What Each Part Of A Linux Command does


Now, we have created the list of installed packages. Keep this list safe. We need it later. Go ahead and format your system.

After reinstalling your Linux box, copy the pkglist.txt file to your system. You can also copy this file to any remote system using scp command. Just make sure you have installed the same version OS on your remote system.

scp pkglist user@remotesystem:/path/

Ex:

scp pkglist.txt root@192.168.43.150:/root/

Finally, install the packages from the pkglist.txt file using the following command as root user:

yum install $(cat /root/pkglist.txt|xargs)

Replace the path of /root/pkglist.txt file with your own.

Done! The package manager will install all packages listed in the pkglist.txt file on your CentOS box.

You can use this pkglist.txt file to all systems on your network. Please note that the package manager will only install the packages from the default official repositories. If you have enabled any other extra repositories on your old system, you need to add them first before installing the softwares.

Create A List Of Installed Packages in Ubuntu and install them later

Create list of all installed packages and save the in a file called pkglist.txt in DEB based systems, run:

dpkg-query -f '${binary:Package}\n' -W > pkglist.txt

Or,

dpkg --get-selections > pkglist.txt

Now, we have created a backup list of installed softwares. Keep this file in a safe location. Format and re-install your Ubuntu machine.

After reinstalling Ubuntu, run the following commands one by one to re-install all software from the backup list.

sudo apt-get install dselect
sudo dpkg --set-selections < pkglist.txt
sudo apt-get dselect-upgrade

Or, combine all of above commands into a single line command and all software from the pkglist.txt file as shown below.

sudo apt-get install $(cat /home/sk/pkglist.txt | awk '{print $1}')

Replace the path of /home/sk/pkglist.txt file with your own.

Please note that if you have used any external repository or PPA in your old system, you need to add them before re-installing software from the backup list.

And, that’s all. Hope this helps. If you find our guides useful, please share them on your social, professional networks, and support OSTechNix.

More good stuffs to come. Stay tuned!

Cheers!

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

  • dipanjan mukherjee

    If the question is reinstall the system with previously loaded pkgs then same thing we can do by using Kickstart file.Even we can do more by using it including partition,PKG install and configuration etc.