4

Is it possible to only install free software packages in Arch Linux? Or perhaps to query a package's license before installing? I suppose you could use -Q to search for the text of a specific license, but it seems overkill.

1

You can do this with expac, an alpm data tool that is in [extra]. For example, to search for Apache licensed software in the repos:

 expac -Ss '%L - %n' '^Apache'

Note: expac does a full search on the target, so additional filtering may be necessary.

Ultimately, though, if you only want free software, you want Parabola Linux, which is Arch-based, but a separate distribution.

1

Licences are included when using the -i / --info options for the -Q / --query or -S / --sync pacman commands. Installing another piece of software as jasonwryan suggests is not necessary.

Here are some example results for pacman -Si glibc:

Name            : glibc
Version         : 2.33-4
Description     : GNU C Library
Architecture    : x86_64
URL             : https://www.gnu.org/software/libc
Licenses        : GPL  LGPL
Groups          : None
Provides        : None
Depends On      : linux-api-headers>=4.10  tzdata  filesystem
Optional Deps   : gd: for memusagestat
Conflicts With  : None
Replaces        : None
Download Size   : 9.84 MiB
Installed Size  : 46.04 MiB
Packager        : Allan McRae <allan@archlinux.org>
Build Date      : Sat 13 Feb 2021 04:39:21 PM EST
Validated By    : MD5 Sum  SHA-256 Sum  Signature

And now we can pipe the output to sed and make it a bash script:

#!/bin/bash

pacman -Si "$@" | sed -E -n 's/Licenses\s*?:\s+(.+)/\1/p'

# "$@"       | pass through arguments (same as $1 $2 $3 ...)

# sed        | stream editor
# -E         | extended (better) regex
# -n         | disable default printing of all lines

# s/         | substitution command
#   Licenses | literal string "Licenses"
#   \s*      | zero or more whitespace characters
#   :        | literal character ":"
#   \s+      | one or more whitespace characters
#   (.+)     | capture rest of line after non-whitespace
# /\1        | replace with first capture group (.+)
# /p         | re-enable printing, but only for matches

Example output for pacman-license glibc curl ffmpeg (comments added):

GPL  LGPL    # glibc
MIT          # curl
GPL3         # ffmpeg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy