{"id":"0b7faf657ccf247b","repo":"rust-lang/cargo","slug":"could-not-find-rustup-home-dir","errorCode":null,"errorMessage":"could not find rustup home dir","messagePattern":"could not find rustup home dir","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/home/src/env.rs","lineNumber":112,"sourceCode":"/// Variant of `cargo_home_with_cwd` where the environment source is\n/// parameterized.\n///\n/// This is specifically to support in-process testing scenarios\n/// as environment variables and user home metadata are normally process global\n/// state. See the `OsEnv` trait.\npub fn rustup_home_with_cwd_env(env: &dyn Env, cwd: &Path) -> io::Result<PathBuf> {\n    match env.var_os(\"RUSTUP_HOME\").filter(|h| !h.is_empty()) {\n        Some(home) => {\n            let home = PathBuf::from(home);\n            if home.is_absolute() {\n                Ok(home)\n            } else {\n                Ok(cwd.join(&home))\n            }\n        }\n        _ => home_dir_with_env(env)\n            .map(|d| d.join(\".rustup\"))\n            .ok_or_else(|| io::Error::new(io::ErrorKind::Other, \"could not find rustup home dir\")),\n    }\n}\n","sourceCodeStart":94,"sourceCodeEnd":115,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/crates/home/src/env.rs#L94-L115","documentation":"Returned by `rustup_home_with_cwd_env` (crates/home/src/env.rs:112) when `RUSTUP_HOME` is unset/empty AND `home_dir_with_env()` returns `None`. Rustup stores toolchains under `~/.rustup`; without a home dir cargo cannot locate the active toolchain and bails.","triggerScenarios":"`RUSTUP_HOME` unset and no resolvable home directory (`std::env::home_dir() -> None`), typically in containers or daemons missing a passwd entry or `HOME`.","commonSituations":"Slim Docker images invoking rustup-managed cargo without `HOME` or `RUSTUP_HOME`; CI runners as a numeric UID with no passwd; systemd services with `HOME=` cleared; chroot builds.","solutions":["Set `RUSTUP_HOME` to the absolute path of the rustup home (e.g. `export RUSTUP_HOME=/opt/rustup`).","Ensure `HOME` points to a writable directory so `~/.rustup` resolves.","Give the runtime user a real passwd entry (`useradd -m`) in containers."],"exampleFix":"# before\nRUN cargo build\n# after\nENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo HOME=/tmp\nRUN cargo build","handlingStrategy":"validation","validationCode":"fn rustup_home_resolvable() -> bool {\n    std::env::var_os(\"RUSTUP_HOME\").filter(|s| !s.is_empty()).is_some() || std::env::home_dir().is_some()\n}\n// assert rustup_home_resolvable() before invoking rustup-managed cargo","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set RUSTUP_HOME explicitly in containers.","Ensure HOME is defined for the cargo user.","Validate environment in CI before the build step."],"tags":["cargo","rustup","environment","home","container"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}