Friday, March 29, 2024

How to Create a List of Installed Packages on Ubuntu


In addition to simply viewing packages on Ubuntu, you may need to save the results for archival purposes or to replicate system configurations. Ubuntu allows you to use the output redirection symbol (>) to save a file containing the names of installed packages.

To do this, use dpkg-query to request information from the dpkg package manager about the installed applications. Then, add -f '${binary:Package}\n' -W to specify the output format.

End the command with the > symbol to indicate where to store the results, namely the completePackage.txt file. Here's the complete command:

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

Alternatively, use the --get-selections option to fetch packages based on their installation status. Here's the command:

sudo dpkg --get-selections > completePackage.txt

Creating a list of packages like this is also useful for replicating installed applications on other devices. To do this, transfer completePackage.txt to the new system and run the following command:

sudo xargs -a completePackage.txt apt install

The xargs command reads the list from the completePackage.txt file. Then, the Linux software installation command adds the same packages to the new system.

You can also use the apt command to replicate packages in Linux. To list installed packages in a file, use the following command:

sudo apt list --installed | awk -F/ -v ORS=" " 'NR>1 {print $1}' > completePackage.txt

After adding the file to another server, install the same packages using the apt-get command:

sudo apt-get install < completePackage.txt

0 comments:

Post a Comment