How to Use `yay` as an AUR Helper on Arch Linux

How to Use yay as an AUR Helper on Arch Linux

Arch Linux is known for its simplicity, transparency, and customization potential. One of the greatest assets of the Arch ecosystem is the Arch User Repository (AUR), a community-driven repository containing user-submitted package build scripts (PKGBUILDs) for software not available in the official Arch repositories. While the AUR is incredibly powerful, interacting with it manually can be tedious and error-prone.

This is where AUR helpers come in, and among the most popular and widely trusted is yay (Yet Another Yaourt). This article provides a comprehensive guide on how to use yay as your AUR helper, covering installation, usage, configuration, and best practices.


What Is yay?

yay is a modern AUR helper written in Go. It is designed to provide a seamless interface for installing, updating, and managing both official repository packages and AUR packages. It effectively replaces older tools like yaourt, combining the functionality of pacman with AUR-specific capabilities.

Key Features of yay

  • Supports both official packages and AUR packages
  • Interactive and user-friendly command-line interface
  • Caches build files for faster rebuilds
  • Allows editing of PKGBUILDs before installation
  • Automatically resolves dependencies from the AUR
  • Maintains pacman compatibility

Prerequisites

Before using yay, make sure you meet the following prerequisites:

  1. You are using Arch Linux or an Arch-based distribution (e.g., Manjaro, EndeavourOS).
  2. You have git and base-devel installed.
  3. You have a user account with sudo privileges.

To install the required tools:

sudo pacman -S git base-devel

These packages are essential for building packages from source and are typically required when working with the AUR.


Installing yay

Since yay is itself an AUR package, you’ll need to install it manually or using another helper if it’s not already installed.

Manual Installation

Here’s how to install yay manually from the AUR:

cd /tmp
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

The makepkg -si command builds the package and installs it, resolving dependencies as needed.

Once installed, verify the installation with:

yay --version

You should see the current version of yay printed.


Basic Usage

yay is designed to be a drop-in replacement for pacman with extended AUR capabilities. Here are some common usage patterns.

Installing Packages

To install a package from the official repos or the AUR:

yay package_name

If the package exists in both the official repositories and the AUR, yay will show both options and ask which one to install.

For example:

yay google-chrome

This will prompt you to select the package source (usually from AUR for google-chrome) and then walk you through the build and installation process.

Updating Packages

To update all installed packages (including AUR):

yay -Syu

This is analogous to:

sudo pacman -Syu

—but with the added benefit of checking and updating AUR packages as well.

Searching for Packages

To search for packages:

yay -Ss package_name

This command searches both the official repositories and the AUR.

To search only in the AUR:

yay -As package_name

To search only in the official repos:

yay -Ss --aur=false package_name

Removing Packages

To remove a package:

yay -Rns package_name

This behaves the same way as the pacman command, recursively removing dependencies that are no longer needed.


Advanced Features

Editing PKGBUILDs

Before installing an AUR package, yay allows you to edit the PKGBUILD or related files if needed:

yay -G package_name

This downloads the PKGBUILD and associated files into a directory, which you can then modify and build manually using makepkg.

Alternatively, during installation, yay will ask if you want to edit build files. You can answer yes if you want to make changes (e.g., enabling specific build flags, adjusting dependencies, etc.).

Cleaning Build Cache

yay stores cached build files in ~/.cache/yay/. Over time, this can grow significantly. You can clean the cache with:

yay -Sc

To remove all cached packages:

yay -Scc

Be cautious: this will remove all stored packages, including those for currently installed AUR packages. If you ever need to rebuild them, yay will need to re-download and recompile everything.

Listing Orphaned Packages

To list orphaned packages (not required by any other installed package):

yay -Qdt

To remove them:

yay -Rns $(yay -Qdtq)

Configuration and Customization

yay has a configuration file located at:

~/.config/yay/config.json

Most users don’t need to modify this file, but if you want to customize yay’s behavior, you can:

  • Change how many results are shown when searching
  • Modify prompt behavior
  • Adjust parallel build settings

Another way to configure yay is through command-line flags. For example, to suppress confirmation prompts:

yay -Syu --noconfirm

Or to automatically clean up dependencies:

yay -Syu --devel --cleanmenu --cleanafter

These options are particularly useful when scripting or automating package management tasks.


Best Practices

Using yay responsibly helps maintain a clean, stable Arch Linux system. Here are a few tips:

  1. Review PKGBUILDs Before Installation: Always inspect the build files of AUR packages. This ensures you’re not installing malicious software.

  2. Keep base-devel Installed: Many AUR packages require tools like make, gcc, fakeroot, etc.

  3. Check Dependencies: Some AUR packages might depend on other AUR packages. yay handles this well, but always check what’s being pulled in.

  4. Avoid Mixing AUR Helpers: Stick to one AUR helper per system to prevent conflicts.

  5. Update Regularly: Use yay -Syu often to keep everything up to date.


Troubleshooting

Here are some common issues and how to resolve them:

1. Build Errors

If a package fails to build:

  • Ensure your system is up to date: yay -Syu
  • Check the AUR page for comments or patches
  • Try building manually using makepkg

2. Signature Verification Issues

Sometimes packages fail with GPG signature errors. To fix this:

gpg --recv-keys <KEY_ID>

You can find the key ID in the error message.

3. Permissions Issues

If yay can’t install a package:

  • Make sure you’re not running yay as root.
  • Ensure your user is in the wheel group and has sudo privileges.

Conclusion

yay is a powerful and user-friendly AUR helper that brings the full breadth of the Arch Linux software ecosystem into your command line. Whether you’re installing popular apps like google-chrome, building cutting-edge development tools, or keeping your system tidy and up-to-date, yay makes the job much easier and safer.

With careful usage and awareness of what you’re installing, yay empowers users to make the most of the AUR while maintaining the Arch philosophy of simplicity, transparency, and control.

Whether you’re a new Arch user or a seasoned veteran, yay deserves a place in your toolkit.