1
0
mirror of https://github.com/tiyn/wiki.git synced 2026-07-26 04:21:34 +02:00
Files
wiki/wiki/linux/package_manager/pacman_and_aur.md

494 lines
16 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Pacman and AUR
In [Arch Linux](/wiki/linux/arch-linux.md) there are 2 main types of
package managers.
The first is Pacman, the default package manager.
For the second type there are many different managers to chose from.
Those managers are handling for the Arch User Repositories (AUR).
In this article yay is used as the go to AUR manager.
yay is also a wrapper for Pacman so yay can be used instead of Pacman to
install and update both AUR and main repository programs.
It features the same syntax.
## Usage
This section addresses various usages of the [Arch Linux](/wiki/linux/arch-linux.md) package
managers.
### Yay
Commands that are available for Pacman are also available for Yay and some other AUR managers.
#### Remove Make Dependencies
This section is based on a
[Reddit comment by AnalShart](https://www.reddit.com/r/archlinux/comments/116dd58/is_it_possible_to_default_remove_make).
The default behavious of Yay is not to remove the make dependencies.
This can be changed by adding the following lines to the config file `~/.config/yay/config.json` or
by editing it accordingly.
```json
{
"removemake": "yes"
}
```
### Installing Packages
This section focuses on the installation of packages.
Before installing new software it is recommended to synchronize the package databases and update the
system.
```sh
pacman -Sy
```
Afterward, install the desired package by replacing `<package>` with its name.
```sh
pacman -S <package>
```
Alternatively both steps can be done simultaneously using the following command.
```sh
pacman -Sy <package>
```
### Removing Packages
Packages can be removed together with their dependencies and configuration files if they are no
longer needed.
This is the recommended way to remove packages as it also gets rid of dependencies that are no
longer required by other packages and its configuration files.
```sh
pacman -Rns <package>
```
### Ignoring Packages
Packages can be ignored by adding the package in `/etc/pacman.conf` under `IgnorePkg`.
In the following example `waybar` is ignored from updates.
To add more packages just add them separated by spaces.
```txt
IgnorePkg = waybar
```
To unignore the package from updates remove it from this line.
### Downgrading Packages
Packages of the AUR can be downgraded by using the
[Downgrade](https://github.com/archlinux-downgrade/downgrade) program.
This program can then easily be used to an AUR package.
This works like the following assuming the package `v4l2loopback-dmks` needs to be downgraded.
```sh
downgrade v4l2loopback-dmks
```
Afterward the target version can be selected and the downgrading process will conclude.
After the downgrade of a package you will get asked if you want to
[ignore future updates](#ignoring-packages).
### Manual Installation of a `PKGBUILD` File
A `PKGBUILD` file is a [shell](/wiki/linux/shell.md) script that contains the installation
information that is required by the Arch Linux.
Using the `makepkg` command it can be installed like the following command shows.
```sh
makepkg -sirc
```
Afterward it is installed on the system and can be further managed (especially uninstalled) by the
Pacman package manager.
### Installing an AUR Program with a Specific Version
The installation of a specific version of an AUR program can be easily achieved.
For this navigate to the AUR page of the program to install.
On the right-hand side click on `View Changes` and select the version you want to install in the
commit list.
Next to `download` a `.tar.gz` file can be downloaded which includes a `PKGBUILD` file.
Afterward it needs to be [uncompressed](/wiki/linux/tar.md#uncompressing-a-tar-archive).
### List and Remove Orphaned Packages
Packages that were installed automatically as dependencies may remain on the system after the
package requiring them has been removed.
These packages are called orphaned packages and can usually be removed safely.
To list all orphaned packages, run the following command.
```sh
pacman -Qdt
```
If the command returns one or more packages, they can be removed together with their unused
configuration files using the following command.
```sh
pacman -Rns $(pacman -Qdtq)
```
It is recommended to review the list of orphaned packages before removing them, as some packages may
still be desired despite no longer being required as a dependency.
### Clear Cache
The cache of all packages except the one installed can be deleted by running the following command.
```sh
pacman -Sc
```
Alternatively the pacman cache can be deleted partly by running the following command which will
clear the cache of pacman except for the latest version.
The amount of versions to keep can be specified by changing the number in the following command
accordingly.
```sh
paccache -rvk1
```
And finally the following command will remove all cached files that belong to uninstalled packages.
Again the number can be changed to keep a specific number of versions.
```sh
paccache -rvuk0
```
Since `yay` mirrors the usage of `pacman` it can be used the same way and will clean both caches.
```sh
yay -Sc
```
Similar to `paccache` a command called [yaycache](https://github.com/aokellermann/yaycache) can be
used.
It follows the same options as `paccache`.
The clearing of the cache can be automated by using a [hook](#hook-clear-cache).
### Enabling `multilib`
`multilib` is a repository that contains 32-bit software and libraries.
By default it is not enabled.
To enable it search and uncomment the following lines in the file `/etc/pacman.conf`.
```txt
[multilib]
Include = /etc/pacman.d/mirrorlist
```
### Searching for Packages by File
Sometimes it is useful to determine which package provides a specific file.
Before searching the file database it has to be synchronized.
```sh
sudo pacman -Fy
```
Afterward, search for one or more file names by replacing `<file>` with the desired file.
```sh
pacman -F <file>
```
For example, this can be used to determine which package provides a missing binary, library or
configuration file.
### Replacing Globally Installed Python Packages
[Python](/wiki/programming_language/python.md) packages installed using
[pip](/wiki/programming_language/python/pip.md) are not managed by Pacman or Yay.
Whenever possible, Python packages should instead be installed using a
[package manager](/wiki/linux/package_manager.md) and the official repositories or the AUR.
This allows them to be updated together with the rest of the system and avoids conflicts with the
system package manager.
However, project-specific dependencies should generally be installed inside
[virtual environments](/wiki/programming_language/python.md#venv-virtual-environments) instead of
globally.
To begin replacing globally installed Python packages, first list all explicitly installed Python
packages.
```sh
pacman -Qet | grep -E '^(python-|python3-)'
```
These packages are usually candidates to keep, as they are already managed by the system package
manager.
Next check for Python packages that exist on the file system but are not owned by Pacman.
The following command searches the global Python installation for unmanaged packages.
```sh
find /usr/lib/python*/site-packages -maxdepth 1 \
| while read package; do
pacman -Qo "$package" >/dev/null 2>&1 || echo "$package"
done
```
Some manually installed packages may instead reside in `/usr/local`.
These can be listed using the following command.
```sh
find /usr/local/lib/python*/site-packages -maxdepth 1
```
For each package that is unmanaged or managed by another source than Pacman or Yay determine the
package name.
Then search whether it is available using Pacman or Yay.
```sh
pacman -Ss <package>
yay -Ss <package>
```
If it is, uninstall the package.
For this pip could be used like shown in the following command.
Finally, reinstall the package using the Pacman or Yay.
```sh
yay -S <package>
```
Note that the packages may not have the same name.
Often the package has a prepended `python-` for Pacmand and Yay packages, however, this does not
have to be the case.
Packages that are not available in either the official repositories or the AUR can still be
installed using tools such as [pip](/wiki/programming_language/python/pip.md) or
[uv](/wiki/programming_language/python/uv.md).
### Hooks
Hooks are commands that are run before or after installation of one or more packages.
They are needed to have the `.hook` extension and can be found inside two directories.
The first one is `/usr/share/libalpm/hooks/`.
The second one is defined in `HookDir` inside the file `/etc/pacman.conf`.
By default it points towards `/etc/pacman.d/hooks`.
Examples of hooks can be found in the following sections.
#### Hook: List Orphans
The following hook will display orphans after any package is update.
It was found in a
[reddit post by IBNash](https://www.reddit.com/r/archlinux/comments/dsnu81/hear_ye_archers_share_your_pacman_hooks/)
which references a
[gist by Strykar](https://gist.github.com/Strykar/3b3cd5bbdabe7e5c77f9414b2b4fe7e8).
```txt
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Searching for orphaned packages...
When = PostTransaction
Exec = /usr/bin/bash -c "/usr/bin/pacman -Qtd || /usr/bin/echo '==> no orphans found.'"
```
#### Hook: Clear Cache
The following hook will [clear the pacman cache](#clear-cache) except for the last version of a package.
It was found in a
[reddit post by IBNash](https://www.reddit.com/r/archlinux/comments/dsnu81/hear_ye_archers_share_your_pacman_hooks/)
which references an
[AUR comment by itaranto](https://aur.archlinux.org/packages/pacman-cleanup-hook).
```txt
[Trigger]
Type = Package
Operation = Remove
Operation = Install
Operation = Upgrade
Target = *
[Action]
Description = Removing unnecessary cached files (keeping the latest one)...
When = PostTransaction
Exec = /usr/bin/paccache -rvk1 && paccache -ruvk0
```
#### Hook: Informant
The following hook will use [informant](https://github.com/bradford-smith94/informant) to check for
Arch News that may require manual intervention and not allow the update if there are news unread.
It was found in a
[reddit post by IBNash](https://www.reddit.com/r/archlinux/comments/dsnu81/hear_ye_archers_share_your_pacman_hooks/)
which references the
[informant Github](https://github.com/bradford-smith94/informant/blob/master/informant.hook).
```txt
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = *
Target = !informant
[Action]
Description = Checking Arch News with Informant...
When = PreTransaction
Exec = /usr/bin/informant check
Depends = informant
AbortOnFail
```
#### Hook: Update Package Mirrorlist
The following hook will use [reflector](https://xyne.dev/projects/reflector/) to update the pacman
mirrorlist.
It will use German mirrors (`-c de`), will list the fastest 15 mirrors (`-n 15`) and only do so if
the mirror was online in the last 24 hours (`-a 24`).
It was found in a
[reddit post by IBNash](https://www.reddit.com/r/archlinux/comments/dsnu81/hear_ye_archers_share_your_pacman_hooks/)
which references the
[pacman-hooks Github](https://github.com/desbma/pacman-hooks/blob/master/reflector/reflector.hook).
```txt
[Trigger]
Operation = Upgrade
Type = Package
Target = pacman-mirrorlist
[Action]
Description = Updating pacman-mirrorlist with reflector...
When = PostTransaction
Depends = reflector
Exec = /bin/bash -c 'reflector -c de -n 15 -a 24 > /etc/pacman.d/mirrorlist ; test -f /etc/pacman.d/mirrorlist.pacnew && mv -v /etc/pacman.d/mirrorlist.{pacnew,orig} || true'
```
#### Hook: Kernel Reboot Needed
The following hook will use determine if a reboot is needed because the kernel was updated.
It was found in a
[reddit commend by progandy](https://www.reddit.com/r/archlinux/comments/dsnu81/comment/f6sogat).
```txt
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = File
Target = usr/lib/modules/*
[Action]
Description = Check for upgrade of running kernel...
When = PostTransaction
Exec = /bin/bash -c "[[ -f \"/proc/modules\" && ! -d \"/usr/lib/modules/$(uname -r)\" ]] && printf '==> WARNING: %s\n -> %s\n' 'Running kernel has been updated or removed!' 'A reboot is required!' || true"
```
## Troubleshooting
This section will focus on errors and the fixing of errors of package managers.
### `/usr/lib/firmware/nvidia/ad104` exists in filesystem linux-firmware-nvidia
This error comes from a decision to split the firmware modules into different parts.
An easy way to fix it is by simply reinstalling the `linux-firmware` package and updating the
packages of the system.
```sh
pacman -Syu linux-firmware
```
### Update Mirrorlist
After a while not updating the system it is possible for the mirrorlist to be
outdated.
This can be fixed by updating it with the following command:
```sh
curl -o /etc/pacman.d/mirrorlist https://archlinux.org/mirrorlist/all/
```
### Error While Importing Keys
Both `yay` and `pacman` use [GPG keys](/wiki/linux/gpg.md).
It is possible that it runs into errors when importing new keys.
If this happens you should try to restart the GPG key server
[as explained in the GPG entry](/wiki/linux/gpg.md#restart-the-gpg-server).
### Unknown Public Key
If the error `ERROR: One or more PGP signatures could not be verified!`, you
have to manually receive the key and trust it.
This can be done [as explained in the GPG entry](/wiki/linux/gpg.md#receive-a-key-and-trust-it).
The identifier of the key usually gets gets printed in the line above the error looking like
`FAILED (unknown public key <KEYID>)`.
### Error During Updating `is marginal trust`
If the error `[...] Key [...] is marginal trust` (also `of unknown trust`) occurs while updating
the system, it can be fixed by running the following commands and then restarting
the update process of the package manager.
```sh
pacman -Sy archlinux-keyring
pacman-key --populate archlinux
pacman-key --refresh-keys
```
### Error During Updating `the following untracked working tree files would be overwritten`
The error `the following untracked working tree files would be overwritten` can happen when the
cache features a changed version of the files used by yay to update the package.
This can easily be fixed by removing the cache of the corresponding package.
### Python `ModuleNotFoundError: No module named...`
This section is based on a
[StackOverflow post by Helen](https://stackoverflow.com/questions/55923868/how-to-fix-modulenotfounderror-no-module-named-setuptools).
In this case the error stems from a missing package.
Normally it can easily be fixed by installing that corresponding package.
But please note that [pyenv](/wiki/programming_language/python.md#pyenv-installation) can hide
packages if the global Python version is set to something other than `system`.
This is especially the case on [Arch Linux-systems](/wiki/linux/arch-linux.md) because Python
packages are also installed via [Pacman or Yay](#arch-linux-pacman-and-yay).
In this case the global Version has to be changed to `system` or the package installed to the
non-system Python version.
### Error `exists in filesystem`
This section is based on a
[reddit post by 194668PT](https://www.reddit.com/r/archlinux/comments/17jempk/pacman_exists_in_filesystem_errors/).
If an error shows up that describes that a file of a package `exists in filesystem` usually a
permission/owner error happened.
This can happen when running `pacman -Syyu`.
To update the package either way the following command can be used.
`<package name>` should be exchanged for the package that throws the error.
```sh
pacman -S --overwrite "*" <package name>
```
### Error `error: could not open file /var/lib/pacman/sync/core.db: Unrecognized archive format`
If the error `error: could not open file /var/lib/pacman/sync/core.db: Unrecognized archive format`
or a similar one with another database file is thrown it can mostly be easily fixed by removing the
database file with the following command.
```txt
rm -rf /var/lib/pacman/sync/*
```
Alternatively and this is probably a bit safer the files can be temporarily be moved somewhere
else and removed after confirming the error was fixed.