rust-lang/cargo · error
no executable for `{}` found in PATH
Error message
no executable for `{}` found in PATH What it means
From resolve_executable (crates/cargo-util/src/paths.rs:124-146). Given a single-component executable name, it walks every directory in $PATH, joins the name (plus the OS exe extension on Windows), and returns the first that is_file(). If none matches, it bails. Cargo uses this to locate external subcommands (cargo-<name>), configured rustc/rustdoc, and helper tools.
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 0e07a15537)
Solutions
- Install the missing tool: `cargo install cargo-<name>` (or the system package).
- Ensure its bin directory is on PATH (e.g. export PATH="$HOME/.cargo/bin:$PATH") and verify with `which cargo-<name>`.
- Reference the tool by absolute path instead of a bare name in config.
- Check for typos in the command/config value.
Example fix
// before $ cargo nextest run error: no executable for `cargo-nextest` found in PATH // after $ cargo install cargo-nextest $ cargo nextest run
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check PATH for an executable before calling resolve_executable
use std::env;
fn executable_on_path(name: &str) -> Option<std::path::PathBuf> {
let path = env::var_os("PATH")?;
for dir in env::split_paths(&path) {
let candidate = dir.join(name);
let with_ext = if std::env::consts::EXE_EXTENSION.is_empty() {
candidate.clone()
} else {
candidate.with_extension(std::env::consts::EXE_EXTENSION)
};
if with_ext.is_file() { return Some(with_ext); }
}
None
}
if executable_on_path("cargo-nextest").is_none() {
eprintln!("install cargo-nextest first");
} Try / catch
match cargo_util::paths::resolve_executable(std::path::Path::new(name)) {
Ok(p) => p,
Err(e) => {
eprintln!("tool `{name}` not found on PATH; install it or pass an absolute path");
return Err(e.into());
}
} Prevention
- Assert required tools exist in your CI image before invoking cargo.
- Prefer absolute paths for configured tools in shared configs.
- Keep ~/.cargo/bin on PATH in shells and CI.
When it happens
Trigger: Running `cargo <x>` where `cargo-<x>` is not installed or not on PATH; a [build] rustc-wrapper / rustc = path pointing at a bare name that isn't found; a custom runner referenced by name. Also reachable from any library code calling cargo_util::paths::resolve_executable on a missing tool.
Common situations: Missing rustfmt, cargo-nextest, sccache, or a project-required cargo-<ext>. A fresh container/CI image without ~/.cargo/bin on PATH. A rustup toolchain switch leaving stale shims. A name typo in config.
Related errors
- `{feature}` is unsupported when inferring the crate name, us
- single file packages cannot be used as dependencies
- `{}` was defined in {} but could not be resolved with {}
- `{}` resolved to non-UTF value (`{}`)
- could not find cargo home dir
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/b83570a94a75c7ed.json.
Report an issue: GitHub.