{"record":{"id":"9b406e417bf1f9f2","repo":"Morganamilo/paru","slug":"can-t-install-aur-package-as-root","errorCode":null,"errorMessage":"can't install AUR package as root","messagePattern":"can't install AUR package as root","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/install.rs","lineNumber":1077,"sourceCode":"            return true;\n        }\n        if self.sysupgrade != 0 || self.refresh != 0 {\n            return false;\n        }\n        if ran_pacman {\n            return false;\n        }\n        aur_targets.is_empty() && upgrades.aur_keep.is_empty() && upgrades.pkgbuild_keep.is_empty()\n    }\n\n    async fn prepare_build(\n        &mut self,\n        config: &Config,\n        cache: &Cache,\n        actions: &mut Actions<'_>,\n    ) -> Result<()> {\n        if !actions.build.is_empty() && nix::unistd::getuid().is_root() {\n            bail!(tr!(\"can't install AUR package as root\"));\n        }\n        if !actions.build.is_empty() && config.args.has_arg(\"w\", \"downloadonly\") {\n            bail!(tr!(\"--downloadonly can't be used for AUR packages\"));\n        }\n\n        let conflicts = check_actions(config, actions, self.install_targets)?;\n\n        self.conflicts = conflicts\n            .0\n            .iter()\n            .map(|c| c.pkg.clone())\n            .chain(conflicts.1.iter().map(|c| c.pkg.clone()))\n            .collect::<HashSet<_>>();\n\n        let c = config.color;\n\n        print_warnings(config, cache, Some(actions));\n","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/Morganamilo/paru/blob/9ac3578807a87858651e81a02586ceb947686e7c/src/install.rs#L1059-L1095","documentation":"prepare_build rejects AUR package builds when the effective user ID is root. Building and installing AUR packages as root is unsafe: makepkg refuses to run as root, and PKGBUILDs execute arbitrary code, so paru bails before any build is scheduled. This is a deliberate safety policy, not an environment failure.","triggerScenarios":"Calling install/prepare_build (via resolve_targets) when actions.build is non-empty (AUR packages to build) and nix::unistd::getuid().is_root() is true — e.g. running `sudo paru -S <aur-pkg>` or `paru -S <aur-pkg>` inside a root shell/container.","commonSituations":"Users running `sudo paru ...` habitually (paru must run as a normal user; it escalates itself via sudo internally); Docker/CI containers that default to root; root shells on recovery/rescue sessions.","solutions":["Run paru as a regular (non-root) user; paru will prompt for the sudo password itself when needed","If you already ran paru with sudo, fix ownership of the paru cache: `sudo chown -R $USER:$USER ~/.cache/paru`","In containers/CI, create a non-root user and run paru under it","Use pacman directly for repository packages if root is genuinely required (repo packages do not hit this path)"],"exampleFix":"// before\n$ sudo paru -S yay\nerror: can't install AUR package as root\n// after\n$ paru -S yay          # run as normal user; paru escalates internally","handlingStrategy":"validation","validationCode":"if nix::unistd::getuid().is_root() {\n    eprintln!(\"refusing to run paru as root; run as a normal user\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never prefix paru with sudo; it escalates itself","Create a build user in containers/CI before invoking paru","Keep ~/.cache/paru owned by your normal user"],"tags":["aur","root","security","permissions"],"backgroundTag":"permission-denied","analyzedSha":"9ac3578807a87858651e81a02586ceb947686e7c","analyzedAt":"2026-09-12T04:57:59.861Z","contentChangedAt":"2026-09-12T04:57:59.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}