Home Arch Linux The Easy Way To Install And Remove A Package Group In Arch Linux

The Easy Way To Install And Remove A Package Group In Arch Linux

By sk
Published: Updated: 8.6K views

The other day, I wanted to test the Deepin DE on my Arch Linux, but I already had some Deepin DE components installed, such as the Deepin screenshot and Deepin Terminal utilities.

The problem is when I want to remove the Deepin DE after testing, I have to manually identify which packages I want to keep. This task is quite time consuming and frustrating.

When I was searching for a straightforward and reliable method to install and remove a package group without impacting existing packages, I found the following viable solution.

In this brief guide, we'll explore how to install a package group and uninstall it later, without removing the packages you previously installed in Arch Linux and its variants.

Install and Remove a Package Group in Arch Linux

First, create a list of packages that belongs to the package group you want to install by using the following command:

$ pacman -Sp deepin --print-format '%n' --needed > deepin-install.txt

The above command will add all packages belongs to the package group deepin in a file named "deepin-install.txt" in your current directory. Please note that It will simply add the package names in the file, not install them.

Here's a breakdown of what each part of the command does:

  1. pacman -Sp: This part of the command is used to simulate the download of packages. The -S option stands for "synchronize" which is typically used to install packages, but when combined with -p (for --print), it instead simulates the installation and shows the URLs from where the packages would be downloaded. This option does not actually download or install the packages.
  2. deepin: This specifies the package or group of packages to be dealt with. In this case, "deepin" refers to a desktop environment or a group of packages related to the Deepin desktop environment.
  3. --print-format '%n': This option customizes the output format of the command. The %n specifier tells pacman to only print the names of the packages, without versions or additional details.
  4. --needed: This flag ensures that the command only considers packages that are not already installed on the system or that are due for an upgrade. It prevents re-listing packages that are already up to date on your system.
  5. > deepin-install.txt: This part of the command redirects the output of the command to a file named deepin-install.txt. Instead of printing to the terminal, the names of the packages that would be installed or downloaded are saved to this file.

In summary, the command pacman -Sp deepin --print-format '%n' --needed > deepin-install.txt simulates the installation of the Deepin desktop environment, listing only the names of the necessary packages that are not already installed or need updating, and saves this list to a file named deepin-install.txt.

This can be useful for creating installation scripts, checking package names without installing them, or preparing for installations on multiple systems.

After taking the list of packages belongs to the deepin package group, install the deepin package group using command:

$ sudo pacman -S deepin

When you want to remove the package group, simply do:

$ sudo pacman -R - < deepin-install.txt

Or,

$ sudo pacman -R $(cat deepin-install.txt)

The above command will only remove the packages mentioned in the deepin-install.txt file.

This isn't just for installing and removing the Deepin package group. You can export the packages from any group to a text file and easily remove those packages listed in the text file if they are no longer required.

For example, if you want to create a list of packages from the vim-plugins package group and save it to a text file called vim-plugins-install.txt, you would run:

$ pacman -Sp vim-plugins --print-format '%n' --needed > vim-plugins-install.txt

This command exports the names of packages belonging to the vim-plugins group to the file.

To install the package group later, simply run the install command:

$ sudo pacman -S vim-plugins

If you no longer need the packages afterward, you can remove them with the following command:

$ sudo pacman -R $(cat vim-plugins-install.txt)

For more details on Pacman usage, refer our following guide:

Also, read the man pages.

$ man pacman

Suggested Read:

You May Also Like

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