'makepkg error "failed to create the directory $BUILDDIR"

Title explains it all really. Whenever I try to makepkg in a directory in non-root I get the previous error followed by "An unknwon error has occured. Exiting...".



Solution 1:[1]

I had the same error when trying to install yaourt on a clean install of arch, what fixed it was changing write permissions with:

sudo chmod a+w

Solution 2:[2]

This error comes from https://git.archlinux.org/pacman.git/tree/scripts/libmakepkg/util/util.sh.in?h=v5.1.0#n88 and means that the directory referred to by the BUILDDIR variable documented in the makepkg.conf(5) manpage, does not exist and you don't have permissions to create it.

So... figure out where this is being set, and fix that.

Note also that the full error message provided by makepkg would include the directory which could not be created, in parentheses after the text of your title. So not only does the title not say it all, it is missing the debugging information specifically added by the developers in order to help users solve the issue as fast as possible.

Solution 3:[3]

his issue comes up in a search—you are most likely trying to run makepkg somewhere outside your home directory, where you do not have permissions.

Move the PKGBUILD (and any associated files) somewhere under another folder like Download or ..... try 100% work.

Solution 4:[4]

I had the same problem trying to install yay. yay does not like to run as root, or under the /root folder (directly or not directly). The problem was that I tried to do everything under /root directory: cloned the yay git package into /root/downloads, then chown the git file (and directory) to user arch, then switched user to arch (su arch), then tried to run makepkg... The solution was simple - switch to arch user first:

su arch
cd /home/arch
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AEinarr Krigsson
Solution 2 eschwartz
Solution 3 massisenergy
Solution 4 Ari