Skip to content

Arch Linux AUR Helper

What Is An AUR Helper?

Arch User Repository (AUR) is a community driven repository by Arch users. The AUR Helper automates various tasks when using AUR such as searching for packages, resolving package dependencies, retrieve packages, build packages, etc.

Warning

AUR Helpers are not supported by Arch Linux. Use at your own risk and understand the manual build process of packages.

Warning

AUR packages are user created. Use at your own risk.

Clearing Package Cache

Packages downloaded by an AUR helper are stored in the cache directory (e.g. ~/.cache/pikaur/pkg). The downloaded packages are not cleared over time even when a package is uninstalled.

With the use of "paccache" script provided by the "pacman-contrib" package, it allows for deletion of all cached versions of installed and uninstalled packages. By default the most recent 3 cached versions will be kept.

Note

For the solutions to work with any particular AUR helper, change the cache directory from "/home/adam/.cache/pikaur/pkg" to the applicable path.

Solution: Manual

  1. First install the required package.
    # pacman -Sy pacman-contrib
    
  2. Remove cached packages.

    Remove all except the most 3 recent cached versions.

    # paccache -c /home/adam/.cache/pikaur/pkg -r
    

    Remove all except the most 2 recent cached versions.

    # paccache -c /home/adam/.cache/pikaur/pkg -rk2
    

  3. Remove all cached versions for uninstalled packages.

    # paccache -c /home/adam/.cache/pikaur/pkg -ruk0
    

Note

A test run of the command paccache can be done by adding the parameter -d (e.g. paccache -dr). This would be a dry run, only displaying possible packages that could be removed.

Solution: Hook

The hook will be ran automatically each time a package is installed, removed or upgraded.

  1. Install dependency.
    # pacman -Sy pacman-contrib
    
  2. Create directory.
    # mkdir -p /etc/pacman.d/hooks
    
  3. Create hook.
    # nano /etc/pacman.d/hooks/pikaur-cache.hook
    
    [Trigger]
    Type = Package
    Operation = Remove
    Operation = Install
    Operation = Upgrade
    Target = *
    
    [Action]
    Description = Remove unused package files cached by pikaur in user's home directory
    Depends = bash
    Depends = pacman-contrib
    When = PostTransaction
    Exec = /usr/bin/bash -c '/usr/bin/paccache -c /home/adam/.cache/pikaur/pkg -r;'
    

Solution: Systemd Timer

Default behaviour is to run weekly to clear unused packages and keep the most 3 recent cached versions.

  1. Install required package.
    # pacman -Sy pacman-contrib
    
  2. Edit timer file as desired (optional).
    # systemctl edit paccache.timer
    
    ### Editing /etc/systemd/system/paccache.timer.d/override.conf
    ### Anything between here and the comment below will become the new contents of the file
    
    OnCalendar=weekly
    
    ### Lines below this comment will be discarded
    
    ### /etc/systemd/system/paccache.timer
    # [Unit]
    # Description=Discard unused packages weekly
    #
    # [Timer]
    # OnCalendar=weekly
    # AccuracySec=1h
    # Persistent=true
    #
    # [Install]
    # WantedBy=timers.target
    
  3. Edit service unit file.

    Change the cache directory.

    # systemctl edit paccache.service
    
    ### Editing /etc/systemd/system/paccache.service.d/override.conf
    ### Anything between here and the comment below will become the new contents of the file
    
    ExecStart=/usr/bin/paccache -c /home/adam/.cache/pikaur/pkg -r
    
    ### Lines below this comment will be discarded
    
    ### /etc/systemd/system/paccache.service
    # [Unit]
    # Description=Discard unused packages
    #
    # [Service]
    # Type=oneshot
    # ExecStart=/usr/bin/paccache -r
    
    1. Enable paccache timer.
    # systemctl enable paccache.timer