Restore –asroot for Yaourt/makepkg Arch (yaourt as root)

Running Yaourt as Root (Workaround for Pacman 4.2+)

Introduction

Since Pacman 4.2, running yaourt as the root user results in an error. This change was introduced to prevent potential system damage caused by building packages with elevated privileges.

For users who operate their system as root, switching users or using aliases can be inconvenient. This guide provides a manual workaround to allow yaourt to run as root.

Warning: Running package build tools as root is not recommended and may cause system instability.

The Problem

makepkg: invalid option '--asroot'

Manual Fix

Step 1: Edit makepkg

vim /usr/bin/makepkg

Step 2: Add asroot Option

Search for OPT_LONG and update it:

OPT_LONG=('allsource' 'check' 'clean' 'cleanbuild' 'config:' 'force' 'geninteg'
'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'noarchive' 'nobuild'
'nocolor' 'nocheck' 'nodeps' 'noextract' 'noprepare' 'nosign' 'pkg:' 'repackage'
'rmdeps' 'sign' 'skipchecksums' 'skipinteg' 'skippgpcheck' 'source' 'syncdeps'
'verifysource' 'version' 'asroot')

Step 3: Remove Root Restriction

Search for EUID and modify this block:

if (( ! INFAKEROOT )); then
    if (( EUID == 0 )); then
        error "$(gettext "Running %s as root is not allowed as it can cause permanent,\n catastrophic damage to your system.")" "makepkg"
        #exit 1
    fi
fi

Update it to:

if (( ! INFAKEROOT )); then
    if (( EUID == 0 )); then
        # Root restriction disabled
        #exit 1
    fi
fi

Optional: Replace with Preconfigured File

Backup Original

cp /usr/bin/makepkg /usr/bin/makepkg_bkp

Replace File

cd ~
sudo cp makepkg /usr/bin/makepkg

Important Notes

  • This fix will be overwritten after system or pacman updates.
  • You will need to reapply the changes after updates.
  • Use with caution as running build tools as root is not recommended.

Conclusion

You should now be able to run:

yaourt

without encountering the --asroot error.

Final Thoughts

If you face any issues or have suggestions, feel free to reach out.