How to use the command 'yay' (with examples)
- Linux
- December 25, 2023
The ‘yay’ command is a utility specifically designed for Arch Linux users to build and install packages from the Arch User Repository (AUR). It functions as an alternative to the ‘pacman’ command and provides additional functionality for searching, installing, updating, and managing packages from both the official repositories and the AUR. By using ‘yay’, Arch Linux users can easily access a vast collection of community-contributed packages and efficiently maintain their system.
Use case 1: Interactively search and install packages from the repos and AUR
Code:
yay package_name|search_term
Motivation: This use case is useful when you want to search for a specific package or browse through available packages in both the official repositories and the AUR. It allows you to interactively select and install packages of interest.
Explanation:
yay
: The command to initiate the search and installation process.package_name|search_term
: The name of the package or the search term you want to look for in the repositories.
Example output:
:: Searching AUR for package_name...
Repository/Package Name: package_name
1) package_name 1.0.0-1 (repo)
2) package_name-git 1.0.0.r15.g141812f-1 (aur)
Enter a number (default=1):
Use case 2: Synchronize and update all packages from the repos and AUR
Code:
yay
Motivation: Regularly updating installed packages is crucial for maintaining system security and stability. This use case ensures that all packages from both the official repositories and the AUR are synchronized and updated to their latest versions.
Explanation:
yay
: The command to initiate the synchronization and update process.
Example output:
:: Synchronizing package databases...
core 133.0 KiB 893 KiB/s 00:00 [------------------------------] 100%
extra 1573.1 KiB 5.07 MiB/s 00:00 [------------------------------] 100%
community 5.3 MiB 6.26 MiB/s 00:01 [------------------------------] 100%
multilib 159.7 KiB 4.29 MiB/s 00:00 [------------------------------] 100%
:: Starting full system upgrade...
Use case 3: Synchronize and update only AUR packages
Code:
yay -Sua
Motivation: In some cases, you may only be interested in updating packages from the AUR while retaining the packages from the official repositories at their current versions. This use case allows you to synchronize and update only the AUR packages.
Explanation:
yay
: The command to initiate the synchronization and update process.-Sua
: Short for-Syu --aur
. This option tells ‘yay’ to synchronize and update packages from both the official repositories (-Syu
) as well as the AUR (--aur
).
Example output:
:: Synchronizing package databases...
core 133.0 KiB 893 KiB/s 00:00 [------------------------------] 100%
extra 1573.1 KiB 3.25 MiB/s 00:00 [------------------------------] 100%
community 5.3 MiB 11.0 MiB/s 00:00 [------------------------------] 100%
multilib 159.7 KiB 5.87 MiB/s 00:00 [------------------------------] 100%
:: Starting AUR update...
Use case 4: Install a new package from the repos and AUR
Code:
yay -S package
Motivation: This use case is used when you want to install a new package from either the official repositories or the AUR. ‘yay’ simplifies the installation process by handling dependencies and allowing you to easily select the package you want to install.
Explanation:
yay
: The command to initiate the installation process.-S
: Short for--sync
. This option tells ‘yay’ to synchronize and install the specified package.package
: The name of the package you want to install.
Example output:
:: Checking for conflicts...
:: Checking for inner conflicts...
[Repo Existing Packages]
[Repo Make: No conflicts found]
[Repo Install: No conflicts found]
[Aur: No packages found]
:: Downloading...
:: Installing...
[Repo Make: No matching PKGBUILD found]
[Repo Install: No matching package found]
:: Retrieving package files...
:: Checking package integrity...
Use case 5: Remove an installed package and both its dependencies and configuration files
Code:
yay -Rns package
Motivation: When you want to completely remove a package and all its dependencies, along with their respective configuration files, this use case comes in handy. It ensures a clean removal of the package, freeing up disk space and eliminating any residual files.
Explanation:
yay
: The command to initiate the removal process.-Rns
: Short for-Rn --nosave
. This option tells ‘yay’ to remove the specified package along with dependencies (-R
) and also removes all configuration files associated with the package (-n
). The--nosave
flag is used to prevent saving backup files.
Example output:
error: target not found: package
Use case 6: Search the package database for a keyword from the repos and AUR
Code:
yay -Ss keyword
Motivation: Searching for packages based on keywords is useful when you know the functionality or purpose of the package you are looking for but not its exact name. This use case allows you to search the package database in both the official repositories and the AUR to find relevant packages.
Explanation:
yay
: The command to initiate the search process.-Ss
: Short for--sync --search
. This option tells ‘yay’ to search for the specified keyword in both the official repositories (--sync
) and the AUR (--search
).keyword
: The keyword you want to search for in the package database.
Example output:
core/package_name 1.0.0-1
Description: A package description
aur/package_name-git 1.0.0.r15.g141812f-1
Description: A package description
Use case 7: Remove orphaned packages
Code:
yay -Yc
Motivation: Over time, as you install, update, and remove packages on your system, orphaned packages may accumulate. These are packages that were installed as dependencies but are no longer needed or required by any other package. Removing orphaned packages helps optimize disk space and ensures a clean package system.
Explanation:
yay
: The command to initiate the removal process.-Yc
: Short for--clean
. This option tells ‘yay’ to remove orphaned packages.
Example output:
:: Removing orphaned packages...
:: Deleting partial packages...
Use case 8: Show statistics for installed packages and system health
Code:
yay -Ps
Motivation: Obtaining statistics about installed packages and system health is useful for system monitoring and troubleshooting. This use case provides valuable insights into the status of installed packages, their versions, and potential issues that need attention.
Explanation:
yay
: The command to initiate the statistics display.-Ps
: Short for--stats
. This option tells ‘yay’ to display statistics for installed packages and system health.
Example output:
Alpm database statistics:
Synchronized repositories: 4
Packages installed: 1000
Disk space used: 2.5GB
Conclusion:
The ‘yay’ command is a powerful utility that enhances the package management process for Arch Linux users. It offers a convenient way to search, install, update, and remove packages from both official repositories and the AUR. By utilizing the various use cases provided above, Arch Linux users can efficiently manage their system and easily access a wide range of community-contributed packages for an enhanced user experience.