{"record":{"id":"f34144d648d91c1f","repo":"denoland/deno","slug":"home-env-var-is-not-defined","errorCode":null,"errorMessage":"${home_env_var} is not defined","messagePattern":"(.+?) is not defined","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tools/installer/global.rs","lineNumber":1305,"sourceCode":"  if let Some(env_dir) = env::var_os(\"DENO_INSTALL_ROOT\")\n    && !env_dir.is_empty()\n  {\n    let env_dir = PathBuf::from(env_dir);\n    return canonicalize_path_maybe_not_exists(&env_dir).with_context(|| {\n      format!(\n        \"Canonicalizing DENO_INSTALL_ROOT ('{}').\",\n        env_dir.display()\n      )\n    });\n  }\n  // Note: on Windows, the $HOME environment variable may be set by users or by\n  // third party software, but it is non-standard and should not be relied upon.\n  let home_env_var = if cfg!(windows) { \"USERPROFILE\" } else { \"HOME\" };\n  let mut home_path =\n    env::var_os(home_env_var)\n      .map(PathBuf::from)\n      .ok_or_else(|| {\n        io::Error::new(\n          io::ErrorKind::NotFound,\n          format!(\"${home_env_var} is not defined\"),\n        )\n      })?;\n  home_path.push(\".deno\");\n  Ok(home_path)\n}\n\n/// Remove all shim files for a given name (the main file plus .cmd/.exe on Windows).\nfn remove_shim_files(\n  installation_dir: &Path,\n  name: &str,\n) -> Result<(), AnyError> {\n  let path = installation_dir.join(name);\n  remove_file_if_exists(&path)?;\n  if cfg!(windows) {\n    remove_file_if_exists(&path.with_extension(\"cmd\"))?;\n    remove_file_if_exists(&path.with_extension(\"exe\"))?;","sourceCodeStart":1287,"sourceCodeEnd":1323,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/cli/tools/installer/global.rs#L1287-L1323","documentation":"When resolving the default global installation root in `cli/tools/installer/global.rs`: if `DENO_INSTALL_ROOT` is unset, Deno falls back to `$HOME/.deno` (`$USERPROFILE` on Windows — the comment notes `$HOME` on Windows is non-standard). If that variable is not defined at all, resolution fails with `io::ErrorKind::NotFound` and this message naming the missing variable.","triggerScenarios":"Running `deno install -g ...` (or any flow that resolves the global bin dir) in an environment where neither `DENO_INSTALL_ROOT` nor `HOME`/`USERPROFILE` is set — bare `docker run` without HOME, `env -i`, stripped systemd/cron units.","commonSituations":"Minimal container images running as a user without a passwd entry/HOME; CI steps that clear the environment; hardened service units using `Environment=` whitelists that omit HOME.","solutions":["Set the home variable in the container/job: `docker run -e HOME=/root ...` or `ENV HOME=/root` in the Dockerfile.","Or set `DENO_INSTALL_ROOT` to an absolute writable directory so the HOME fallback is never consulted.","For systemd/cron, add `Environment=HOME=/var/lib/app` (or USERPROFILE equivalent) to the unit/service definition."],"exampleFix":"# before\n$ docker run denoland/deno:latest deno install -g jsr:@luca/lume\n# → $HOME is not defined\n\n# after (either works)\n$ docker run -e HOME=/root denoland/deno:latest deno install -g jsr:@luca/lume\n$ DENO_INSTALL_ROOT=/usr/local/bin deno install -g jsr:@luca/lume","handlingStrategy":"validation","validationCode":"#!/bin/sh\n# POSIX: abort early with a clear message if the home variable is missing\n: \"${HOME:?HOME is not set — deno install -g needs it or set DENO_INSTALL_ROOT}\"\n# Windows (PowerShell):\n# if (-not $env:USERPROFILE) { throw 'USERPROFILE is not set' }","typeGuard":null,"tryCatchPattern":"try {\n  await Deno.run({ cmd: [\"deno\", \"install\", \"-g\", pkg] });\n} catch {\n  // re-run with DENO_INSTALL_ROOT set to a known writable dir\n}","preventionTips":["Set ENV HOME in Dockerfiles that run deno install","Add Environment=HOME=... to systemd/cron units invoking Deno","Prefer explicit DENO_INSTALL_ROOT in automation to avoid HOME dependence"],"tags":["deno-install","environment-variable","home","global-install","container"],"backgroundTag":"missing-home-env-var","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}