{"record":{"id":"76d950523a507e26","repo":"sxyazi/yazi","slug":"failed-to-determine-the-cargo-bin-directory","errorCode":null,"errorMessage":"failed to determine the Cargo bin directory","messagePattern":"failed to determine the Cargo bin directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-build/src/common.rs","lineNumber":14,"sourceCode":"use std::{env, ffi::OsString, fs, path::{Path, PathBuf}, process::Command};\n\nuse anyhow::{Context, Result, bail, ensure};\n\npub(super) fn cargo() -> OsString { env::var_os(\"CARGO\").unwrap_or_else(|| \"cargo\".into()) }\n\npub(super) fn cargo_bin_dir() -> Result<PathBuf> {\n\tif let Some(root) = env::var_os(\"CARGO_INSTALL_ROOT\") {\n\t\treturn Ok(PathBuf::from(root).join(\"bin\"));\n\t}\n\tif let Some(home) = cargo_home_dir() {\n\t\treturn Ok(home.join(\"bin\"));\n\t}\n\tbail!(\"failed to determine the Cargo bin directory\")\n}\n\nfn cargo_home_dir() -> Option<PathBuf> {\n\tenv::var_os(\"CARGO_HOME\").map(PathBuf::from).or_else(|| {\n\t\tenv::var_os(\"HOME\")\n\t\t\t.or_else(|| env::var_os(\"USERPROFILE\"))\n\t\t\t.map(|home| PathBuf::from(home).join(\".cargo\"))\n\t})\n}\n\npub(super) fn workspace_root() -> Result<PathBuf> {\n\tPath::new(env!(\"CARGO_MANIFEST_DIR\"))\n\t\t.parent()\n\t\t.map(Path::to_owned)\n\t\t.context(\"yazi-build must be inside the Yazi workspace\")\n}\n\npub(super) fn is_linux_target(target: &str) -> bool {","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-build/src/common.rs#L1-L32","documentation":"`cargo_bin_dir` resolves the directory where `cargo install` places binaries: first from `CARGO_INSTALL_ROOT`, then from `CARGO_HOME` or `HOME`/`USERPROFILE` (via `cargo_home_dir`), appending `bin` in each case. If none of these environment variables is set, it bails because it cannot determine where the binary should be installed.","triggerScenarios":"Running the `install` task (`cargo yazi install`) in an environment with none of `CARGO_INSTALL_ROOT`, `CARGO_HOME`, `HOME`, or `USERPROFILE` set — e.g. a stripped-down container, systemd service, or CI job with a minimal env.","commonSituations":"Docker builds with `ENV` cleared; cron/systemd units lacking `$HOME`; running under `env -i`; Windows CI missing `USERPROFILE`.","solutions":["Set `CARGO_HOME` (e.g. `export CARGO_HOME=$HOME/.cargo`) before running `cargo yazi install`.","Set `CARGO_INSTALL_ROOT` to an explicit install root (e.g. `/usr/local`) to bypass home detection entirely.","Ensure `HOME` (Unix) or `USERPROFILE` (Windows) is present in the execution environment."],"exampleFix":"// before (Dockerfile)\nRUN cargo yazi install\n// after\nRUN CARGO_HOME=/usr/local/cargo cargo yazi install --bin-dir /usr/local/bin","handlingStrategy":"validation","validationCode":"if [ -z \"$CARGO_HOME\" ] && [ -z \"$CARGO_INSTALL_ROOT\" ] && [ -z \"$HOME\" ] && [ -z \"$USERPROFILE\" ]; then\n  echo \"set CARGO_HOME before running cargo yazi install\" >&2; exit 1;\nfi","typeGuard":null,"tryCatchPattern":"match cargo_bin_dir() {\n  Ok(dir) => dir,\n  Err(_) => {\n    eprintln!(\"set CARGO_HOME or CARGO_INSTALL_ROOT and retry\");\n    std::process::exit(1);\n  }\n}","preventionTips":["Set CARGO_HOME explicitly in Dockerfiles, CI jobs, and service units.","Use CARGO_INSTALL_ROOT for non-interactive installs to a fixed path.","Sanity-check `echo $HOME` in minimal environments before installing."],"tags":["environment","cargo","installation"],"backgroundTag":"missing-env-var","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}