rust-lang/cargo · error

no executable for ` ` found in PATH

Error message

no executable for `{}` found in PATH

What it means

resolve_executable searches each directory in the PATH environment variable for a file matching the given executable name (appending the platform EXE_EXTENSION if needed). If no candidate is an existing file, it bails with 'no executable for ... found in PATH'. The lookup only runs when the name is a single path component (no separators).

Solutions

  1. Install the missing executable and ensure it is on PATH.
  2. Verify PATH contains the install directory: `echo $PATH` / `where <tool>` (Windows) / `which <tool>` (Unix).
  3. Pass an absolute or relative path to the executable instead of a bare name so the PATH search is bypassed.
  4. On Windows, confirm the file has the .exe extension.

Example fix

// before
resolve_executable(Path::new("my-tool"))  // not on PATH
// after
resolve_executable(Path::new("/opt/my-tool/bin/my-tool"))
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check PATH before resolving
let name = "my-tool";
let found = std::env::var_os("PATH").map(|p| std::env::split_paths(&p)
    .any(|d| d.join(name).is_file())).unwrap_or(false);
if !found { eprintln!("{name} not on PATH; install it first"); }

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Calling resolve_executable with a bare tool name (e.g. 'rustc', 'git', 'cmake') when that tool is not installed or not on PATH; PATH is empty/unset; the executable lacks the expected extension on Windows.

Common situations: Missing build dependency (linker, ar, cmake, git) in CI; container images without the tool installed; wrong PATH in a spawned process; Windows tools missing .exe extension.

Related errors


AI-assisted analysis of rust-lang/cargo@42eee92bc9 (2026-08-11). Data as JSON: /api/errors/b83570a94a75c7ed. Report an issue: GitHub.

Appendix: source

Thrown at crates/cargo-util/src/paths.rs:142

pub fn resolve_executable(exec: &Path) -> Result<PathBuf> {
    if exec.components().count() == 1 {
        let paths = env::var_os("PATH").ok_or_else(|| anyhow::format_err!("no PATH"))?;
        let candidates = env::split_paths(&paths).flat_map(|path| {
            let candidate = path.join(&exec);
            let with_exe = if env::consts::EXE_EXTENSION.is_empty() {
                None
            } else {
                Some(candidate.with_extension(env::consts::EXE_EXTENSION))
            };
            iter::once(candidate).chain(with_exe)
        });
        for candidate in candidates {
            if candidate.is_file() {
                return Ok(candidate);
            }
        }

        anyhow::bail!("no executable for `{}` found in PATH", exec.display())
    } else {
        Ok(exec.into())
    }
}

/// Returns metadata for a file (follows symlinks).
///
/// Equivalent to [`std::fs::metadata`] with better error messages.
pub fn metadata<P: AsRef<Path>>(path: P) -> Result<Metadata> {
    let path = path.as_ref();
    std::fs::metadata(path)
        .with_context(|| format!("failed to load metadata for path `{}`", path.display()))
}

/// Returns metadata for a file without following symlinks.
///
/// Equivalent to [`std::fs::metadata`] with better error messages.
pub fn symlink_metadata<P: AsRef<Path>>(path: P) -> Result<Metadata> {

View on GitHub (pinned to 42eee92bc9)