{"record":{"id":"9ab6f9a76affb5eb","repo":"denoland/deno","slug":"you-do-not-have-write-permission-to","errorCode":null,"errorMessage":"You do not have write permission to {}","messagePattern":"You do not have write permission to (.+?)","errorType":"exception","errorClass":"AnyError","httpStatus":null,"severity":"error","filePath":"cli/tools/upgrade.rs","lineNumber":2017,"sourceCode":"}\n\nfn set_exe_permissions(\n  current_exe_path: &Path,\n  output_exe_path: &Path,\n) -> Result<std::fs::Permissions, AnyError> {\n  let Ok(metadata) = fs::metadata(output_exe_path) else {\n    let metadata = fs::metadata(current_exe_path).with_context(|| {\n      format!(\n        \"failed to get metadata of the current executable at '{}'\",\n        current_exe_path.display()\n      )\n    })?;\n    return Ok(metadata.permissions());\n  };\n\n  let permissions = metadata.permissions();\n  if permissions.readonly() {\n    bail!(\n      \"You do not have write permission to {}\",\n      output_exe_path.display()\n    );\n  }\n  #[cfg(unix)]\n  if std::os::unix::fs::MetadataExt::uid(&metadata) == 0\n    && !nix::unistd::Uid::effective().is_root()\n  {\n    bail!(\n      concat!(\n        \"You don't have write permission to {} because it's owned by root.\\n\",\n        \"Consider updating deno through your package manager if its installed from it.\\n\",\n        \"Otherwise run `deno upgrade` as root.\",\n      ),\n      output_exe_path.display()\n    );\n  }\n  Ok(permissions)","sourceCodeStart":1999,"sourceCodeEnd":2035,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/tools/upgrade.rs#L1999-L2035","documentation":"Before replacing the binary, Deno checks write access to the output executable path (falling back to the current exe's metadata if the output does not exist yet). If the file's permission bits mark it read-only, the upgrade aborts with this message naming the path. It is a filesystem permission guard, distinct from the root-ownership case handled separately.","triggerScenarios":"`deno upgrade` where the deno binary (or the configured `--output` path) has a read-only bit set — e.g. chmod 444/555, an immutable file attribute, or an output path on a read-only mount. Checked via `permissions.readonly()` at cli/tools/upgrade.rs:2017.","commonSituations":"Hardened system installs where binaries are deliberately read-only; files made immutable by admin tooling; upgrading from a system-managed location mounted read-only; custom `--output` pointing at a locked path.","solutions":["Make the binary writable: `chmod u+w <path>` (as the message's path), then re-run `deno upgrade`.","If it is system/package-manager-managed, update through that package manager instead of `deno upgrade`.","Point the upgrade at a writable location: `deno upgrade --output <writable-dir>/deno` and adjust PATH.","Remove immutable attributes if set (`chattr -i` on Linux)."],"exampleFix":"# before\ndeno upgrade  # You do not have write permission to /usr/local/bin/deno\n\n# after\nsudo chmod u+w /usr/local/bin/deno   # or: chattr -i /usr/local/bin/deno\ndeno upgrade","handlingStrategy":"validation","validationCode":"deno_bin=\"$(command -v deno)\"\n[ -w \"$deno_bin\" ] || { echo \"deno not writable — chmod or use --output\"; exit 1; }\ndeno upgrade","typeGuard":null,"tryCatchPattern":"deno upgrade 2>err.log || { grep -q 'write permission' err.log && chmod u+w \"$(command -v deno)\"; }","preventionTips":["Install deno in a user-writable location (~/.deno/bin) rather than system paths.","Check `test -w` on the binary before scripted upgrades.","Use `--output` to target a writable path when the install dir is locked."],"tags":["upgrade","permissions","filesystem","readonly"],"backgroundTag":"permission-denied","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}