Home Linux Commands Create A List Of Installed Packages And Install Them Later From The List In Arch Linux

Create A List Of Installed Packages And Install Them Later From The List In Arch Linux

By sk
Published: Updated: 11.6K views

Today, I am going to teach you how to create a list of installed packages and install them later from the backup list in Arch Linux system after doing a clean installation.

This method can be useful for error reporting or discussion of installed packages with your colleagues or Technical support team. More importantly, if you want similar set of packages in a group of Arch Linux systems, this is one such a way to achieve it.

Create A List Of Installed Packages And Install Them Later In Arch Linux

Let us generate the list of explicitly installed packages using command:

$ pacman -Qqe > pkglist.txt

This command will create a list of explicitly installed packages in alphabetical order and save them in a text file called "pkglist.txt".

Here,

  • Q - Queries the package database. This option allows you to view installed packages and their files, other useful meta-information about individual packages (dependencies, conflicts, install date, build date, size).
  • q - Shows less information for certain query operations. This is useful when pacman’s output is processed in a script.
  • e - Lists explicitly installed packages that are not required by any other package.
  • pkglist.txt - It is the output file where you store the list of installed files.

Save the "pkglist.txt" file in USB drive or somewhere safe.

Now, format and reinstall the system. After reinstalling your system, copy the "pkglist.txt" file to your newly installed system and run the following command to install packages from the backup list.

$ sudo pacman -S - < pkglist.txt

Just in case, the backup list includes foreign packages, such as AUR packages, remove them first, and then install the rest of packages using command:

$ sudo pacman -S $(comm -12 <(pacman -Slq | sort) <(sort pkglist.txt))

The above command will you remove the foreign packages. Type 'y' and hit ENTER to remove them. Finally, type 'y' to install the rest of the packages from the list.

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

You don't need to install all packages one by one. Pacman will read the list and install packages listed in there.

To remove all the packages on your newly installed system that are not mentioned in the backup list, run:

$ sudo pacman -Rsu $(comm -23 <(pacman -Qq | sort) <(sort pkglist.txt))

For more details, refer the man pages.

$ man pacman

This handy method will make your life easier when you want to reinstall your Arch Linux system or its derivatives like EndeavourOS and Manjaro Linux. Don't bother installing packages one by one. Just export the list of installed packages to a file, and save it to a safe place, and then install the packages from the backup list after reinstalling your Arch system.

You can also use the same backup list to any newly installed Arch Systems on your home/office. It will save you a lot of time from searching and installing packages one by one.

Want to know how to do the same in YUM based and DEB based systems? Great! Refer the following guide.

Reference:

You May Also Like

3 comments

Dan St.André May 5, 2017 - 12:57 am

Does a similar article exist for Debian-family (*buntu, Mint, etc) package managers? My search efforts only found this article.

~~~ 8d:-} Dan

Reply
dataloss February 9, 2018 - 10:17 pm

Works but doesn’t play nice afterwords with maintenance commands like;
sudo pacman -Rns $(pacman -Qtdq)
sudo pacman -Sc
sudo paccache -rk 1
sudo paccache -ruk0
It’s as if the packages are not registered in the pacman as installed and being used database or whatever and are treated as not needed/not used packages by pacman, you can test the listed commands above and see what I mean jest “don’t” press “y” especially with the first one.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More