Purpose
The purpose of this article is to describe and explore ways to copy or backup your currently existing installed software titles into a single file for later use. We can then use this file to reinstall the software onto another system or clone the existing software across multiple Linux systems on or across a network. This method also prevents the need to install software titles one by one.
We have used a file named “allthethings.txt” to store a list of all of the currently installed software on our systems.
Keep this list safe! If you format your system with the file still on it, you will lose all of the information needed to reinstall the software.
[su_box title=”Note:” style=”glass” box_color=”#3ac6eb” radius=”20″]Using this method with the various package managers noted will only install the packages from the default official repositories or PPA’s. If you have enabled and installed other software from repositories other than the official default locations or PPA’s, they will not be included in the installs. If you need to install those additional software titles, you will need to add the repositories where the software is located before running the install in this manner.
[/su_box]
To summarize, the following commands will accomplish the following on CentOS 7 & Ubuntu 18:
- List all software.
- List the number of packages installed.
- Search for a specific package.
- Add installed software to a text file.
- Install software from a text file.
CentOS7
RPM
List all software:
[root@host ~]# rpm -qa
List number of packages installed:
[root@host ~]# rpm -qa | wc -l
Search for a specific package:
[root@host ~]# rpm -q tmux
Add installed software to a text file:
[root@host ~]# rpm -qa | tr '\n' ' ' > allthethings.txt
Install software from a text file:
There exists no method to restore from a file list using RPM. Yum must be used.
YUM
List all software:
[root@host ~]# yum list installed
List number of packages installed:
[root@host ~]# yum list installed | wc -l
Search for a specific package:
[root@host ~]# yum list installed | grep unzip
Add installed software to a text file:
[root@host ~]# yum list installed | awk '{print $1}' | tr '\n' ' ' > allthethings.txt
Install software from a text file:
[root@host ~]# yum -y install $(cat allthethings.txt)
Ubuntu18
APT
List all software:
[root@host ~]# apt list --installed
List number of packages installed:
[root@host ~]# apt list --installed | wc -l
Search for specific package:
[root@host ~]# apt list --installed | grep PHP
Add installed software to a text file:
[root@host ~]# apt list --installed > allthethings.txt
Or
[root@host ~]# apt list --installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > allthethings.txt
Install software from a text file:
[root@host ~]# xargs -a allthethings.txt apt install
DPKG
List all software:
[root@host ~]# dpkg -l | grep ^ii
List number of packages installed:
[root@host ~]# dpkg -l | grep ^ii | wc -l
Search for specific package:
[root@host ~]# dpkg -l | grep ^ii | grep -i PHP
Add installed software to a text file:
[root@host ~]# dpkg-query -f '${binary:Package}\n' -W > allthethings.txt
or
[root@host ~]# dpkg --get-selections > allthethings.txt
Install software from a text file:
[root@host ~]# apt-get install < allthethings.txt
Further Detail
After reinstalling your base Linux system, copy or upload a copy of the ‘allthethings.txt’ file to your system. Please ensure you have installed the same version of your OS on your new or remote system. Once the file has been copied, install the packages from the allthethings.txt file using one of the above noted commands as the root user. The package manager will install all of the packages listed in the ‘allthethings.txt’ file on your system.
Talk To An Expert Today!
And there you have it! You can now feel safe when reinstalling all of your existing software on your systems into a new system! And if you’re still having issues creating a software install list on your virtual private server, cloud hosting, or dedicated server solution, you can contact our support team 24/7.
David Singer