{"record":{"id":"df8a692d235a1511","repo":"microsoft/aspire","slug":"cannot-write-to-installation-directory-0-please-run-the","errorCode":null,"errorMessage":"Cannot write to installation directory '{0}'. Please run the update with elevated permissions (e.g., using sudo on Linux/macOS).","messagePattern":"Cannot write to installation directory '(.+?)'\\. Please run the update with elevated permissions \\(e\\.g\\., using sudo on Linux/macOS\\)\\.","errorType":"exception","errorClass":"UnauthorizedAccessException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Commands/UpdateCommand.cs","lineNumber":869,"sourceCode":"            }\n            catch\n            {\n                // If anything goes wrong, restore the backup\n                _logger.LogWarning(\"Update failed, restoring backup\");\n                if (backupPath is not null && File.Exists(backupPath))\n                {\n                    if (File.Exists(targetExePath))\n                    {\n                        File.Delete(targetExePath);\n                    }\n                    File.Move(backupPath, targetExePath);\n                }\n                throw;\n            }\n        }\n        catch (UnauthorizedAccessException)\n        {\n            throw new UnauthorizedAccessException(\n                string.Format(CultureInfo.CurrentCulture, UpdateCommandStrings.NoWritePermissionToInstallDirectory, installDir));\n        }\n        finally\n        {\n            // Clean up temp directories\n            CleanupDirectory(tempExtractDir);\n            CleanupDirectory(Path.GetDirectoryName(archivePath)!);\n        }\n    }\n\n    private static bool IsInPath(string directory, IEnvironment environment)\n    {\n        var pathEnv = Environment.GetEnvironmentVariable(\"PATH\");\n        if (string.IsNullOrEmpty(pathEnv))\n        {\n            return false;\n        }\n","sourceCodeStart":851,"sourceCodeEnd":887,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Commands/UpdateCommand.cs#L851-L887","documentation":"During archive self-update, file operations into the CLI's installation directory (backup, replace) may raise UnauthorizedAccessException when the process lacks write permission. The command wraps it and rethrows with a clearer message including the install directory and the elevation hint (sudo on Linux/macOS).","triggerScenarios":"`aspire update --self` when the CLI was installed to a root-owned location such as /usr/local/bin on Linux/macOS, or a protected Program Files directory on Windows, and the update is run without elevated privileges.","commonSituations":"System-wide installs performed with sudo but later updated from a normal user shell; CI containers running as non-root with the binary owned by root.","solutions":["Re-run the update with elevated permissions: `sudo aspire update --self` (Linux/macOS) or an elevated shell on Windows","Change ownership/permissions of the install directory so your user can write it","Reinstall the CLI into a user-writable location (e.g. ~/.aspire/bin) with the installer script","On Windows, take ownership of the install directory or use an admin terminal"],"exampleFix":"// before\naspire update --self\n// after\nsudo aspire update --self","handlingStrategy":"validation","validationCode":"var installDir = Path.GetDirectoryName(Environment.ProcessPath)!;\nif (!HasWriteAccess(installDir))\n    Console.Error.WriteLine(\"No write access to install dir; run with sudo or an elevated shell.\");","typeGuard":null,"tryCatchPattern":"try { await UpdateSelfAsync(); }\ncatch (UnauthorizedAccessException ex) { Console.Error.WriteLine($\"Permission denied: {ex.Message}\"); return 1; }","preventionTips":["Install the CLI to a user-writable location if you update frequently without sudo","Pair sudo usage with -E or correct ownership so the update can run elevated","Check directory ACLs/ownership before scripted updates"],"tags":["cli","self-update","permissions"],"backgroundTag":"file-write-permission-denied","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}