How to Install and Use Yay on Arch Linux

Pacman, the default package manager on Arch-based distros is powerful, but it lacks the functionality of downloading packages from the Arch User Repository (AUR). The AUR is a community-maintained repository providing thousands of third-party packages in the form of installation scripts, also known as PKGBUILDs.

To install packages using these PKGBUILDs, you need to use an AUR helper like Yay. Yay doesn't come preinstalled on Arch Linux and isn't available in the official Arch repositories either. So how do you install Yay to download packages from the AUR on your Arch desktop? Let's find out.

How to Install Yay on Arch Linux

As mentioned above, Yay is only available in the Arch User Repository. Note that you can manually install packages from the AUR without using an AUR helper (similar to how you'll install Yay), but as the name suggests, an "AUR helper" assists you in the installation process, making it easier for you to install packages with minimum user interaction.

To install Yay on Arch Linux, first, download the following dependencies:

sudo pacman -S --needed base-devel git 

Then, clone the Yay repository using the git clone command:

git clone https://aur.archlinux.org/yay.git 

Change your present working directory to the newly-downloaded yay folder using the cd command:

cd yay 

Finally, use the makepkg command to build and install Yay:

makepkg -si 

If the above command throws the "cannot find the fakeroot binary" error, make sure you've successfully installed the base-devel package and then re-run the command.

In addition to Arch Linux, this method works for other Arch-based distributions as well, including Manjaro, EndeavourOS, and Garuda Linux.

Once done, verify the installation by checking the version of Yay installed:

yay --version 

If the output returns a version number, you have succeeded in installing Yay.

The AUR isn't originally built for use on Linux distros other than Arch Linux and its derivatives (like Ubuntu and Linux Mint). On such distributions, you can use Pacstall, an AUR-inspired package manager that provides pacscripts for installing software.

How to Manage AUR Packages Using Yay

Yay and Pacman commands have a lot in common. For example, to install a new package using Pacman or Yay, you use the -S flag, whereas to remove one, you've to use the -R option.

Let's begin with package management on Arch Linux using Yay.

Searching for AUR Packages

Like Pacman, Yay allows users to search for packages before installing them. If you're unsure about the name of a particular package, you can use the yay command with the search term to find related packages:

yay searchterm 

For example, to search for packages with "chrome" in their name:

yay chrome 

Output:

To search for a package on both the official repositories and AUR, use the -Ss flag:

yay -Ss google-chrome 

You can also specify multiple keywords to perform a narrow, more focused search as follows:

yay -S term1 term2 

The aforementioned command will first search for term1 and then narrow down the results by searching for term2 in the returned results.

Installing Packages With Yay

As discussed before, to install packages with Yay, simply specify the package name after the -S flag:

yay -S packagename 

To install the Google Chrome AUR package using Yay:

yay -S google-chrome 

The installation process isn't completely automatic and you might have to enter your superuser password in the middle of the installation.

To only get the PKGBUILD of a package, use the -G or --getpkgbuild flag:

yay -G google-chrome 

You can also choose to print the PKGBUILD by using the -p flag with -G:

yay -Gp google-chrome 

Output:

Removing Packages With Yay

When you don't need an AUR package and want to remove it from your system, use the -R option:

yay -R packagename 

For example, to uninstall Google Chrome, run:

yay -R google-chrome 

If you want to remove the package along with its dependencies, append the -ns flag to the previous command:

yay -Rns google-chrome 

Upgrading AUR Packages

Invoking the yay command without any arguments will perform a full system upgrade similar to the pacman -Syu command.

This command will also synchronize and upgrade packages from the official repositories in addition to the AUR.

To only update AUR packages, use the -Sua flag with the command:

yay -Sua 

If you don't want to update a package on Arch Linux, you'll have to modify the configuration file located at /etc/pacman.conf. Linux also allows you to downgrade packages on your system if you want.

Using Yay to Remove Unnecessary Dependencies

If not taken care of, unused dependencies can quickly pile up and consume a huge chunk of your system storage. You can either choose to remove the dependencies along with the packages by using the -Rns flag each time you remove something, or take the better route by sweeping them away all at once using the -Yc flag:

yay -Yc 

The -Y in the above command stands for "Yay" and will only perform operations on packages installed using Yay.

Some Additional Yay Commands

To print package statistics and system health with Yay, run the following command:

yay -Ps 

Output:

In case you need help with the commands, you can easily get command-line help using the --help flag:

yay --help 

Alternatively, you can view the Yay manual page using:

man yay 

The AUR Has Got Everything You Need!

Now that installing AUR packages is a breeze for you, go check out the AUR and search for software that you've always wanted to install on Linux. There's a good chance that it'll be available in the repository.

Keep in mind that using the AUR also poses a security risk. Since anyone can add their PKGBUILD to the AUR, these installation scripts aren't often reviewed properly. But that doesn't mean you should stop downloading packages from the AUR altogether.

Instead, minimize the risk by reviewing the PKGBUILDs before installing the packages. Not only will this keep your system safe, but you'll also learn how packages in the AUR work.

ncG1vNJzZmivp6x7rq3KnqysnZ%2Bbe6S7zGigp6uklrmtecCnm2ato5p6uq3YZpirm5hiuaq61LFm