Skip to content
Latchkey

Rust "rustup: command not found" in CI

The shell could not find rustup (or cargo) on PATH. Either Rust was never installed on the runner, or it is installed but ~/.cargo/bin was never added to PATH for this step.

What this error means

A step calling rustup or cargo fails instantly with "command not found", even on an image that supposedly has Rust. Common on bare images or after installing rustup in a previous step without exporting PATH.

Terminal
./ci/build.sh: line 3: rustup: command not found
# or
cargo: command not found

Common causes

Rust not installed on the runner

A minimal base image ships no Rust toolchain. rustup and cargo simply do not exist until you install them.

~/.cargo/bin not on PATH

rustup installs binaries to ~/.cargo/bin. If that directory isn’t on PATH - or a later step starts a fresh shell that never sourced ~/.cargo/env - the commands aren’t found.

How to fix it

Install rustup and add it to PATH

Terminal
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
. "$HOME/.cargo/env"
rustc --version

Persist cargo bin to the job PATH

In GitHub Actions, write ~/.cargo/bin to $GITHUB_PATH so every later step finds cargo.

.github/workflows/ci.yml
- run: |
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
    echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
- run: cargo build   # now resolves

How to prevent it

  • Use a setup action (e.g. dtolnay/rust-toolchain) instead of installing by hand.
  • Add ~/.cargo/bin to $GITHUB_PATH so all steps see cargo.
  • Use the official rust Docker image when you control the container.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →