Loading...
X

How to install (or remove) packages using a regular expression in pacman

How to install packages with a wildcard (or a regular expression) in pacman

If you try to use wildcards in the pacman command to install multiple packages at once, you won't be able to do it.

For example, I want to install all packages whose names start with “kodi-addon-” with one command. Let's try to do this with the following command:

sudo pacman -S kodi-addon-*

The command will fail with an error:

error: target not found: kodi-addon-*

This is doubly annoying, since in Debian-based distributions using the apt package manager, similar syntax is valid, for example:

sudo apt install kodi-audiodecoder-*

The packages of interest to us were found by part of the name and a wildcard:

Note, selecting 'kodi-audiodecoder-sidplay' for glob 'kodi-audiodecoder-*'
Note, selecting 'kodi-audiodecoder-openmpt' for glob 'kodi-audiodecoder-*'
Note, selecting 'kodi-audiodecoder-fluidsynth' for glob 'kodi-audiodecoder-*'
Installing:
  kodi-audiodecoder-fluidsynth  kodi-audiodecoder-openmpt  kodi-audiodecoder-sidplay

In pacman, wildcards (and regular expressions) only work when searching for packages, but not when installing them. However, you can combine these two actions (searching for packages and installing them) in one command:

sudo pacman -S $(pacman -Ssq 'REGEX')

REGEX can be:

  1. part of the package name
  2. part of the package name and wildcards
  3. regular expression

Note: note that if the search string (regular expression) contains characters that have special meaning to the shell, then you need to put the whole string in quotes. If you use part of the package name without, for example, “*” or “|”, then you can omit the quotes.

For example, the following command will install all packages whose name matches the pattern “kodi-addon-”:

sudo pacman -S $(pacman -Ssq kodi-addon-)

Let's look at an example of using a regular expression – the following command will install all packages whose names match the patterns “kodi-addon-audioencoder-*” OR “kodi-addon-imagedecoder-*”:

sudo pacman -S $(pacman -Ssq 'kodi-addon-audioencoder-|kodi-addon-imagedecoder-')

Before performing the installation, you can check which packages will be installed, for this use the following command:

pacman -Ssq 'REGULAR_EXPRESSION'

For example:

pacman -Ssq 'kodi-addon-audioencoder-|kodi-addon-imagedecoder-'

This command will output a list packages:

kodi-addon-audioencoder-flac
kodi-addon-audioencoder-lame
kodi-addon-audioencoder-vorbis
kodi-addon-audioencoder-wav
kodi-addon-imagedecoder-heif
kodi-addon-imagedecoder-raw

Another check before installing packages:

pacman -Ssq kodi-addon-

The following packages will be found that match the specified pattern name:

kodi-addon-audioencoder-flac
kodi-addon-audioencoder-lame
kodi-addon-audioencoder-vorbis
kodi-addon-audioencoder-wav
kodi-addon-imagedecoder-heif
kodi-addon-imagedecoder-raw
kodi-addon-inputstream-adaptive
kodi-addon-inputstream-rtmp
kodi-addon-peripheral-joystick
kodi-addon-screensaver-asteroids
kodi-addon-screensaver-biogenesis
kodi-addon-screensaver-greynetic
kodi-addon-screensaver-matrixtrails
kodi-addon-screensaver-pingpong
kodi-addon-screensaver-pyro
kodi-addon-screensaver-stars
kodi-addon-visualization-projectm
kodi-addon-visualization-shadertoy
kodi-addon-visualization-spectrum
kodi-addon-visualization-waveform

How in pacman remove packages with a wildcard (regular expression)

To remove packages by part of the name or a regular expression, you can use the following command:

sudo pacman -R $(pacman -Qsq 'REGEXP')

Examples:

sudo pacman -R $(pacman -Qsq 'kodi-addon-audioencoder-|kodi-addon-imagedecoder-')

sudo pacman -R $(pacman -Qsq 'kodi-addon-')

If you want to check in advance which packages will be removed, use a command like this:

pacman -Qsq 'REGEXP'

Note that this is not the same command that was used to check which packages will be installed by the specified regular expression. In the first section we used the -S operation (search all packages in the repository), and for removal we use the -Q operation (search only installed packages).

Examples:

pacman -Qsq 'kodi-addon-'
pacman -Qsq 'kodi-addon-audioencoder-|kodi-addon-imagedecoder-'

Leave Your Observation

Your email address will not be published. Required fields are marked *